@cocreate/crud-server
Advanced tools
Comparing version 1.34.2 to 1.34.3
@@ -0,1 +1,8 @@ | ||
## [1.34.3](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.34.2...v1.34.3) (2024-01-30) | ||
### Bug Fixes | ||
* removed getHostOld() and getOrganizationOld() ([956c472](https://github.com/CoCreate-app/CoCreate-crud-server/commit/956c472c4ebbc8eeb36f4d612f19ec70ffba241c)) | ||
## [1.34.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.34.1...v1.34.2) (2024-01-18) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@cocreate/crud-server", | ||
"version": "1.34.2", | ||
"version": "1.34.3", | ||
"description": "CoCreate-crud-server", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -66,14 +66,4 @@ 'use strict'; | ||
let organization = await this.getOrganization(data.organization_id) | ||
let organization = await this.getOrganization(data) | ||
// if (data.host && this.hosts[data.host]) | ||
// organization = await this.getHost(data.host) | ||
// else | ||
// organization = await this.getOrganization(data.organization_id) | ||
// if (data.host) | ||
// organization = await this.getHost(data.organization_id) | ||
// else | ||
// organization = await this.getOrganization(data.organization_id) | ||
if (organization.error) | ||
@@ -120,3 +110,3 @@ return resolve(organization) | ||
this.send(platformUpdate) | ||
// this.send(platformUpdate) | ||
} | ||
@@ -208,35 +198,25 @@ } | ||
async getHost(host) { | ||
if (this.hosts[host]) { | ||
return await this.hosts[host] | ||
async getOrganization(data) { | ||
if (this.hosts[data.host]) { | ||
return await this.hosts[data.host] | ||
} else if (this.organizations[data.organization_id]) { | ||
return await this.organizations[data.organization_id] | ||
} else { | ||
let organization_id = null | ||
let platform = true | ||
if (this.organizations[organization_id]) { | ||
let org = await this.organizations[organization_id] | ||
organization_id = org._id | ||
platform = false | ||
if (data.organization_id) { | ||
this.organizations[data.organization_id] = this.getOrg(data) | ||
this.organizations[data.organization_id] = await this.organizations[data.organization_id] | ||
return this.organizations[data.organization_id] | ||
} else if (data.host) { | ||
// this.hosts[data.host] = this.getOrg(data) | ||
this.hosts[data.host] = await this.getOrg(data) | ||
return this.hosts[data.host] | ||
} | ||
this.hosts[host] = this.getOrg(organization_id, host, platform) | ||
this.hosts[host] = await this.hosts[host] | ||
return this.hosts[host] | ||
} | ||
} | ||
async getOrganization(organization_id, platform) { | ||
if (this.organizations[organization_id]) { | ||
return await this.organizations[organization_id] | ||
} else { | ||
this.organizations[organization_id] = this.getOrg(organization_id, null, platform) | ||
this.organizations[organization_id] = await this.organizations[organization_id] | ||
return this.organizations[organization_id] | ||
} | ||
} | ||
async getOrg(organization_id, host, platform = true) { | ||
let data = { | ||
async getOrg(data) { | ||
let query = { | ||
method: 'object.read', | ||
host, | ||
host: data.host, | ||
database: this.config.organization_id, | ||
@@ -247,10 +227,10 @@ array: 'organizations', | ||
if (!platform) | ||
data.database = data.organization_id = organization_id | ||
if (this.organizations[data.organization_id]) | ||
data.database = data.organization_id = data.organization_id | ||
if (organization_id) | ||
data.object = [{ _id: organization_id }] | ||
else if (host) | ||
data.$filter = { | ||
query: { host: { $elemMatch: { name: { $in: [host] } } } }, | ||
if (data.organization_id) | ||
query.object = [{ _id: data.organization_id }] | ||
else if (data.host) | ||
query.$filter = { | ||
query: { host: { $elemMatch: { name: { $in: [data.host] } } } }, | ||
limit: 1 | ||
@@ -261,6 +241,6 @@ } | ||
if (!this.organizations[data.organization_id] && data.organization_id === this.config.organization_id) | ||
this.organizations[data.organization_id] = { ...this.config, isConfig: true } | ||
if (!this.organizations[query.organization_id] && query.organization_id === this.config.organization_id) | ||
this.organizations[query.organization_id] = { ...this.config, isConfig: true } | ||
let organization = await this.send(data) | ||
let organization = await this.send(query) | ||
@@ -270,17 +250,22 @@ if (organization | ||
&& organization.object[0]) { | ||
this.organizations[organization.object[0]._id] = organization.object[0] | ||
if (platform) { | ||
delete data.$filter | ||
data.database = data.organization_id = organization.object[0]._id | ||
let org = await this.send(data) | ||
if (!this.organizations[organization.object[0]._id] || this.organizations[query.organization_id].isConfig) { | ||
this.organizations[organization.object[0]._id] = organization.object[0] | ||
delete query.$filter | ||
query.database = query.organization_id = organization.object[0]._id | ||
let org = await this.send(query) | ||
if (org | ||
&& org.object | ||
&& org.object[0]) { | ||
if (data.host) | ||
this.hosts[data.host] = org.object[0] | ||
return org.object[0] | ||
} else { | ||
return { serverOrganization: false, error: 'An organization could not be found in the specified dbUrl' } | ||
} | ||
} else { | ||
if (data.host) | ||
this.hosts[data.host] = organization.object[0] | ||
return organization.object[0] | ||
} | ||
return organization.object[0] | ||
} | ||
@@ -290,3 +275,2 @@ return { serverOrganization: false, error: 'An organization could not be found' } | ||
errorHandler(data, error, database, array) { | ||
@@ -293,0 +277,0 @@ if (typeof error == 'object') |
126350
284