@cocreate/crud-server
Advanced tools
Comparing version 1.28.11 to 1.29.0
@@ -0,1 +1,15 @@ | ||
# [1.29.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.28.11...v1.29.0) (2023-11-03) | ||
### Bug Fixes | ||
* removed limit slice ([26c6cc1](https://github.com/CoCreate-app/CoCreate-crud-server/commit/26c6cc1c3f8c760b0c8d90f9ab0923896c2cce59)) | ||
* update dependencies to the lates versions ([e2ddb24](https://github.com/CoCreate-app/CoCreate-crud-server/commit/e2ddb2440daa92bdcd547b355ef75933eced2947)) | ||
* update method to use object.update etc ([b6400da](https://github.com/CoCreate-app/CoCreate-crud-server/commit/b6400da90f16fd98d59ef18b06f40980f91b67d7)) | ||
### Features | ||
* get orgainization and storage once using promise ([1dac253](https://github.com/CoCreate-app/CoCreate-crud-server/commit/1dac2539cb5167da803130d0a94458e02318f63e)) | ||
## [1.28.11](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.28.10...v1.28.11) (2023-10-25) | ||
@@ -2,0 +16,0 @@ |
{ | ||
"name": "@cocreate/crud-server", | ||
"version": "1.28.11", | ||
"version": "1.29.0", | ||
"description": "CoCreate-crud-server", | ||
@@ -43,4 +43,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@cocreate/config": "^1.6.5", | ||
"@cocreate/utils": "^1.26.1", | ||
"@cocreate/config": "^1.6.6", | ||
"@cocreate/utils": "^1.26.2", | ||
"csvtojson": "^2.0.10", | ||
@@ -47,0 +47,0 @@ "json-2-csv": "^3.10.3" |
@@ -11,3 +11,3 @@ 'use strict'; | ||
this.ObjectId = ObjectId | ||
this.storages = new Map(); | ||
this.organizations = {}; | ||
this.init() | ||
@@ -47,8 +47,8 @@ } | ||
if (this.wsManager) { | ||
const type = ['storage', 'database', 'array', 'index', 'object']; | ||
const method = ['create', 'read', 'update', 'delete']; | ||
const type = ['storage', 'database', 'array', 'index', 'object']; | ||
for (let i = 0; i < method.length; i++) { | ||
for (let j = 0; j < type.length; j++) { | ||
const action = method[i] + '.' + type[j]; | ||
for (let i = 0; i < type.length; i++) { | ||
for (let j = 0; j < method.length; j++) { | ||
const action = type[i] + '.' + method[j]; | ||
this.wsManager.on(action, (data) => | ||
@@ -81,32 +81,6 @@ this.send(data)) | ||
let storages = this.storages.get(data.organization_id) | ||
if (storages === false) | ||
return resolve({ serverStorage: false, error: 'A storage or database could not be found' }) | ||
let storages = await this.getStorage(data) | ||
if (storages.error) | ||
return resolve(storages) | ||
if (!storages) { | ||
if (data.organization_id === this.config.organization_id) { | ||
storages = this.config.storage | ||
if (storages) | ||
this.storages.set(data.organization_id, storages) | ||
} else { | ||
let organization = await this.send({ | ||
method: 'read.object', | ||
database: this.config.organization_id, | ||
array: 'organizations', | ||
object: [{ _id: data.organization_id }], | ||
organization_id: this.config.organization_id | ||
}) | ||
if (organization | ||
&& organization.object | ||
&& organization.object[0]) { | ||
if (organization.object[0].storage) | ||
this.storages.set(data.organization_id, organization.object[0].storage) | ||
else | ||
return resolve({ serverStorage: false, error: 'A storage url could not be found' }) | ||
} else { | ||
return resolve({ serverOrganization: false, error: 'An organization could not be found' }) | ||
} | ||
} | ||
} | ||
if (data['timeStamp']) | ||
@@ -118,3 +92,3 @@ data['timeStamp'] = new Date(data['timeStamp']) | ||
// TODO: manage error handling if if no method defined | ||
if (data.method.startsWith('update.') && data.upsert != false) | ||
if (data.method.endsWith('.update') && data.upsert != false) | ||
data.upsert = true | ||
@@ -126,3 +100,3 @@ | ||
if (data.method.startsWith('update.object') && data.organization_id !== this.config.organization_id) { | ||
if (data.method === 'object.update' && data.organization_id !== this.config.organization_id) { | ||
let syncKeys | ||
@@ -152,5 +126,3 @@ if (data.array === 'organizations') | ||
} | ||
} | ||
} | ||
@@ -179,10 +151,7 @@ | ||
if (data.$filter) { | ||
if (!data.type) | ||
data.type = data.method.split('.').pop() | ||
let type = data.method.split(".")[0] | ||
if (data.$filter.sort && data.$filter.sort.length) | ||
data[data.type] = sortData(data[data.type], data.$filter.sort) | ||
if (data.$filter.index && data.$filter.limit) | ||
data[data.type] = data[data.type].slice(data.$filter.index, data.$filter.limit) | ||
data[type] = sortData(data[type], data.$filter.sort) | ||
data.$filter.count = data[data.type].length | ||
data.$filter.count = data[type].length | ||
} | ||
@@ -222,2 +191,44 @@ | ||
async getStorage(data) { | ||
if (this.organizations[data.organization_id]) | ||
return await this.organizations[data.organization_id] | ||
if (data.organization_id === this.config.organization_id) { | ||
this.organizations[data.organization_id] = this.config.storage | ||
return this.config.storage | ||
} else { | ||
if (this.organizations[data.organization_id]) { | ||
return await this.organizations[data.organization_id] | ||
} else { | ||
this.organizations[data.organization_id] = this.getOrganization(data) | ||
this.organizations[data.organization_id] = await this.organizations[data.organization_id] | ||
return this.organizations[data.organization_id] | ||
} | ||
} | ||
} | ||
async getOrganization(data) { | ||
let organization = await this.send({ | ||
method: 'object.read', | ||
database: this.config.organization_id, | ||
array: 'organizations', | ||
object: [{ _id: data.organization_id }], | ||
organization_id: this.config.organization_id | ||
}) | ||
if (organization | ||
&& organization.object | ||
&& organization.object[0]) { | ||
if (organization.object[0].storage) { | ||
return organization.object[0].storage | ||
} else | ||
return { serverStorage: false, error: 'A storage url could not be found' } | ||
} else { | ||
return { serverOrganization: false, error: 'An organization could not be found' } | ||
} | ||
} | ||
errorHandler(data, error, database, array) { | ||
@@ -224,0 +235,0 @@ if (typeof error == 'object') |
118970
246
Updated@cocreate/config@^1.6.6
Updated@cocreate/utils@^1.26.2