@cocreate/crud-server
Advanced tools
Comparing version 1.3.4 to 1.4.0
@@ -0,1 +1,8 @@ | ||
# [1.4.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.4...v1.4.0) (2022-04-01) | ||
### Features | ||
* readCollections to return a list of collections ([2ad15d4](https://github.com/CoCreate-app/CoCreate-crud-server/commit/2ad15d43baf22c6dabbf56582cac182dec8876ad)) | ||
## [1.3.4](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.3...v1.3.4) (2022-03-06) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@cocreate/crud-server", | ||
"version": "1.3.4", | ||
"version": "1.4.0", | ||
"description": "CoCreate-crud-server", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -12,3 +12,3 @@ const {ObjectID} = require("mongodb"); | ||
this.wsManager.on('readDocumentList', (socket, data, socketInfo) => this.readDocumentList(socket, data, socketInfo)); | ||
this.wsManager.on('readCollectionList', (socket, data, socketInfo) => this.readCollectionList(socket, data, socketInfo)); | ||
this.wsManager.on('readCollections', (socket, data, socketInfo) => this.readCollections(socket, data, socketInfo)); | ||
} | ||
@@ -44,3 +44,2 @@ | ||
is_collection: true | false, | ||
//. case fetch document case | ||
@@ -58,4 +57,2 @@ export: true | false | ||
} | ||
// await sleep(3000) | ||
@@ -65,3 +62,3 @@ const self = this; | ||
if (req_data['is_collection']) { | ||
var result = await this.readCollectionList(socket, req_data, socketInfo); | ||
var result = await this.readCollections(socket, req_data, socketInfo); | ||
return; | ||
@@ -135,21 +132,13 @@ } | ||
async readCollectionList(socket, data, socketInfo) { | ||
async readCollections(socket, data, socketInfo) { | ||
try { | ||
var collections = []; | ||
const db = this.dbClient.db(req_data['organization_id']); | ||
collections = await db.listCollections().toArray().then(infos => { | ||
var result = []; | ||
infos.forEach(function(item) { | ||
let __uuid = item.info.uuid.toString('hex') | ||
result.push({ | ||
name: item.name, | ||
_id: __uuid, | ||
id: __uuid, | ||
}); | ||
}) | ||
return result; | ||
}) | ||
this.wsManager.send(socket, 'readCollectionList', {...data, data: collections }, data['organization_id'], socketInfo); | ||
const self = this; | ||
const db = this.dbClient.db(data['organization_id']); | ||
db.listCollections().toArray(function(error, result) { | ||
if (!error && result && result.length > 0) { | ||
self.wsManager.send(socket, 'readCollections', {...data, data: result }, data['organization_id'], socketInfo); | ||
} | ||
}) | ||
} catch(error) { | ||
console.log('readCollections error', error); | ||
this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo); | ||
@@ -159,3 +148,2 @@ } | ||
/** | ||
@@ -162,0 +150,0 @@ * function that make query from data |
80352
738