@cocreate/crud-server 1.34.1 → 1.34.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.34.3](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.34.2...v1.34.3) (2024-01-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * removed getHostOld() and getOrganizationOld() ([956c472](https://github.com/CoCreate-app/CoCreate-crud-server/commit/956c472c4ebbc8eeb36f4d612f19ec70ffba241c))
7
+
8
+ ## [1.34.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.34.1...v1.34.2) (2024-01-18)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * improved handling of organization object ([7798bf7](https://github.com/CoCreate-app/CoCreate-crud-server/commit/7798bf7b4feba9b0bcc226c37d890b3c6b9b5e99))
14
+
1
15
  ## [1.34.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.34.0...v1.34.1) (2024-01-17)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.34.1",
3
+ "version": "1.34.3",
4
4
  "description": "CoCreate-crud-server",
5
5
  "keywords": [
6
6
  "cocreate-crud",
package/src/index.js CHANGED
@@ -63,7 +63,8 @@ class CoCreateCrudServer {
63
63
  if (!data.organization_id || !this.config)
64
64
  return resolve()
65
65
 
66
- let organization = await this.getOrganization(data.organization_id)
66
+ let organization = await this.getOrganization(data)
67
+
67
68
  if (organization.error)
68
69
  return resolve(organization)
69
70
 
@@ -105,7 +106,7 @@ class CoCreateCrudServer {
105
106
  }
106
107
  }
107
108
 
108
- this.send(platformUpdate)
109
+ // this.send(platformUpdate)
109
110
  }
110
111
  }
111
112
  }
@@ -192,64 +193,79 @@ class CoCreateCrudServer {
192
193
  });
193
194
  }
194
195
 
195
- async getHost(host) {
196
- if (this.hosts[host]) {
197
- return await this.hosts[host]
198
- } else {
199
- this.hosts[host] = this.getOrg(null, host)
200
- this.hosts[host] = await this.hosts[host]
201
- return this.hosts[host]
202
- }
203
-
204
- }
205
196
 
206
- async getOrganization(organization_id, platform) {
207
- if (this.organizations[organization_id]) {
208
- return await this.organizations[organization_id]
197
+ async getOrganization(data) {
198
+ if (this.hosts[data.host]) {
199
+ return await this.hosts[data.host]
200
+ } else if (this.organizations[data.organization_id]) {
201
+ return await this.organizations[data.organization_id]
209
202
  } else {
210
- this.organizations[organization_id] = this.getOrg(organization_id, null, platform)
211
- this.organizations[organization_id] = await this.organizations[organization_id]
212
- return this.organizations[organization_id]
203
+ if (data.organization_id) {
204
+ this.organizations[data.organization_id] = this.getOrg(data)
205
+ this.organizations[data.organization_id] = await this.organizations[data.organization_id]
206
+ return this.organizations[data.organization_id]
207
+ } else if (data.host) {
208
+ // this.hosts[data.host] = this.getOrg(data)
209
+ this.hosts[data.host] = await this.getOrg(data)
210
+ return this.hosts[data.host]
211
+ }
213
212
  }
214
213
  }
215
214
 
216
- async getOrg(organization_id, host, platform = true) {
217
- let data = {
215
+ async getOrg(data) {
216
+ let query = {
218
217
  method: 'object.read',
219
- host,
218
+ host: data.host,
220
219
  database: this.config.organization_id,
221
220
  array: 'organizations',
222
221
  organization_id: this.config.organization_id
223
222
  }
224
223
 
225
- if (!platform)
226
- data.database = data.organization_id = organization_id
224
+ if (this.organizations[data.organization_id])
225
+ data.database = data.organization_id = data.organization_id
227
226
 
228
- if (organization_id)
229
- data.object = [{ _id: organization_id }]
230
- else if (host)
231
- data.$filter = {
232
- query: { host: { $elemMatch: { name: { $in: [host] } } } }
227
+ if (data.organization_id)
228
+ query.object = [{ _id: data.organization_id }]
229
+ else if (data.host)
230
+ query.$filter = {
231
+ query: { host: { $elemMatch: { name: { $in: [data.host] } } } },
232
+ limit: 1
233
233
  }
234
234
  else
235
235
  return { serverOrganization: false, error: 'An organization could not be found' }
236
236
 
237
- if (data.organization_id === this.config.organization_id)
238
- this.organizations[organization_id] = this.config
237
+ if (!this.organizations[query.organization_id] && query.organization_id === this.config.organization_id)
238
+ this.organizations[query.organization_id] = { ...this.config, isConfig: true }
239
239
 
240
- let organization = await this.send(data)
240
+ let organization = await this.send(query)
241
241
 
242
242
  if (organization
243
243
  && organization.object
244
244
  && organization.object[0]) {
245
- return organization.object[0]
246
- } else {
247
- return { serverOrganization: false, error: 'An organization could not be found' }
245
+ if (!this.organizations[organization.object[0]._id] || this.organizations[query.organization_id].isConfig) {
246
+ this.organizations[organization.object[0]._id] = organization.object[0]
247
+
248
+ delete query.$filter
249
+ query.database = query.organization_id = organization.object[0]._id
250
+ let org = await this.send(query)
251
+ if (org
252
+ && org.object
253
+ && org.object[0]) {
254
+ if (data.host)
255
+ this.hosts[data.host] = org.object[0]
256
+ return org.object[0]
257
+ } else {
258
+ return { serverOrganization: false, error: 'An organization could not be found in the specified dbUrl' }
259
+ }
260
+ } else {
261
+ if (data.host)
262
+ this.hosts[data.host] = organization.object[0]
263
+ return organization.object[0]
264
+ }
248
265
  }
249
-
266
+ return { serverOrganization: false, error: 'An organization could not be found' }
250
267
  }
251
268
 
252
-
253
269
  errorHandler(data, error, database, array) {
254
270
  if (typeof error == 'object')
255
271
  error['storage'] = 'mongodb'