@cocreate/crud-server 1.34.2 → 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 +7 -0
- package/package.json +1 -1
- package/src/index.js +41 -57
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
## [1.34.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.34.1...v1.34.2) (2024-01-18)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -63,17 +63,7 @@ class CoCreateCrudServer {
|
|
|
63
63
|
if (!data.organization_id || !this.config)
|
|
64
64
|
return resolve()
|
|
65
65
|
|
|
66
|
-
let organization = await this.getOrganization(data
|
|
67
|
-
|
|
68
|
-
// if (data.host && this.hosts[data.host])
|
|
69
|
-
// organization = await this.getHost(data.host)
|
|
70
|
-
// else
|
|
71
|
-
// organization = await this.getOrganization(data.organization_id)
|
|
72
|
-
|
|
73
|
-
// if (data.host)
|
|
74
|
-
// organization = await this.getHost(data.organization_id)
|
|
75
|
-
// else
|
|
76
|
-
// organization = await this.getOrganization(data.organization_id)
|
|
66
|
+
let organization = await this.getOrganization(data)
|
|
77
67
|
|
|
78
68
|
if (organization.error)
|
|
79
69
|
return resolve(organization)
|
|
@@ -116,7 +106,7 @@ class CoCreateCrudServer {
|
|
|
116
106
|
}
|
|
117
107
|
}
|
|
118
108
|
|
|
119
|
-
this.send(platformUpdate)
|
|
109
|
+
// this.send(platformUpdate)
|
|
120
110
|
}
|
|
121
111
|
}
|
|
122
112
|
}
|
|
@@ -203,85 +193,79 @@ class CoCreateCrudServer {
|
|
|
203
193
|
});
|
|
204
194
|
}
|
|
205
195
|
|
|
206
|
-
async getHost(host) {
|
|
207
|
-
if (this.hosts[host]) {
|
|
208
|
-
return await this.hosts[host]
|
|
209
|
-
} else {
|
|
210
|
-
let organization_id = null
|
|
211
|
-
let platform = true
|
|
212
|
-
if (this.organizations[organization_id]) {
|
|
213
|
-
let org = await this.organizations[organization_id]
|
|
214
|
-
organization_id = org._id
|
|
215
|
-
platform = false
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
this.hosts[host] = this.getOrg(organization_id, host, platform)
|
|
219
|
-
this.hosts[host] = await this.hosts[host]
|
|
220
|
-
return this.hosts[host]
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
}
|
|
224
196
|
|
|
225
|
-
async getOrganization(
|
|
226
|
-
if (this.
|
|
227
|
-
return await this.
|
|
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]
|
|
228
202
|
} else {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
+
}
|
|
232
212
|
}
|
|
233
213
|
}
|
|
234
214
|
|
|
235
|
-
async getOrg(
|
|
236
|
-
let
|
|
215
|
+
async getOrg(data) {
|
|
216
|
+
let query = {
|
|
237
217
|
method: 'object.read',
|
|
238
|
-
host,
|
|
218
|
+
host: data.host,
|
|
239
219
|
database: this.config.organization_id,
|
|
240
220
|
array: 'organizations',
|
|
241
221
|
organization_id: this.config.organization_id
|
|
242
222
|
}
|
|
243
223
|
|
|
244
|
-
if (
|
|
245
|
-
data.database = data.organization_id = organization_id
|
|
224
|
+
if (this.organizations[data.organization_id])
|
|
225
|
+
data.database = data.organization_id = data.organization_id
|
|
246
226
|
|
|
247
|
-
if (organization_id)
|
|
248
|
-
|
|
249
|
-
else if (host)
|
|
250
|
-
|
|
251
|
-
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] } } } },
|
|
252
232
|
limit: 1
|
|
253
233
|
}
|
|
254
234
|
else
|
|
255
235
|
return { serverOrganization: false, error: 'An organization could not be found' }
|
|
256
236
|
|
|
257
|
-
if (!this.organizations[
|
|
258
|
-
this.organizations[
|
|
237
|
+
if (!this.organizations[query.organization_id] && query.organization_id === this.config.organization_id)
|
|
238
|
+
this.organizations[query.organization_id] = { ...this.config, isConfig: true }
|
|
259
239
|
|
|
260
|
-
let organization = await this.send(
|
|
240
|
+
let organization = await this.send(query)
|
|
261
241
|
|
|
262
242
|
if (organization
|
|
263
243
|
&& organization.object
|
|
264
244
|
&& organization.object[0]) {
|
|
265
|
-
this.organizations[organization.object[0]._id]
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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)
|
|
270
251
|
if (org
|
|
271
252
|
&& org.object
|
|
272
253
|
&& org.object[0]) {
|
|
254
|
+
if (data.host)
|
|
255
|
+
this.hosts[data.host] = org.object[0]
|
|
273
256
|
return org.object[0]
|
|
274
|
-
|
|
275
257
|
} else {
|
|
276
258
|
return { serverOrganization: false, error: 'An organization could not be found in the specified dbUrl' }
|
|
277
259
|
}
|
|
260
|
+
} else {
|
|
261
|
+
if (data.host)
|
|
262
|
+
this.hosts[data.host] = organization.object[0]
|
|
263
|
+
return organization.object[0]
|
|
278
264
|
}
|
|
279
|
-
return organization.object[0]
|
|
280
265
|
}
|
|
281
266
|
return { serverOrganization: false, error: 'An organization could not be found' }
|
|
282
267
|
}
|
|
283
268
|
|
|
284
|
-
|
|
285
269
|
errorHandler(data, error, database, array) {
|
|
286
270
|
if (typeof error == 'object')
|
|
287
271
|
error['storage'] = 'mongodb'
|