@cocreate/crud-server
Advanced tools
Comparing version 1.3.3 to 1.3.4
@@ -0,1 +1,10 @@ | ||
## [1.3.4](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.3...v1.3.4) (2022-03-06) | ||
### Bug Fixes | ||
* broadcast_sender if condition removed and handeled by socket ([c2a0a6d](https://github.com/CoCreate-app/CoCreate-crud-server/commit/c2a0a6d79d331e56160cd9ddaf8a7e521e2270e8)) | ||
* removed param isExact from broadcast as it can be handled by param room ([e709e36](https://github.com/CoCreate-app/CoCreate-crud-server/commit/e709e366493759399f371f2ffc3c630e415f8daa)) | ||
* update param roomInfo to socketInfo ([f50edc9](https://github.com/CoCreate-app/CoCreate-crud-server/commit/f50edc91ee4695f6a652fd8a8c943feac24ba80a)) | ||
## [1.3.3](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.2...v1.3.3) (2022-03-05) | ||
@@ -2,0 +11,0 @@ |
{ | ||
"name": "@cocreate/crud-server", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "CoCreate-crud-server", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -16,7 +16,7 @@ const json2csv = require("json-2-csv") | ||
if (this.wsManager) { | ||
// this.wsManager.on('exportDB', (socket, data, roomInfo) => this.exportData(socket, data, roomInfo)); | ||
// this.wsManager.on('importDB', (socket, data, roomInfo) => this.importData(socket, data, roomInfo)); | ||
// this.wsManager.on('importFile2DB', (socket, data, roomInfo) => this.importData(socket, data, roomInfo)); | ||
// this.wsManager.on('exportDB', (socket, data, socketInfo) => this.exportData(socket, data, socketInfo)); | ||
// this.wsManager.on('importDB', (socket, data, socketInfo) => this.importData(socket, data, socketInfo)); | ||
// this.wsManager.on('importFile2DB', (socket, data, socketInfo) => this.importData(socket, data, socketInfo)); | ||
// this.wsManager.on('downloadData', (socket, data, roomInfo) => this.downloadData(socket, data, roomInfo)) | ||
// this.wsManager.on('downloadData', (socket, data, socketInfo) => this.downloadData(socket, data, socketInfo)) | ||
} | ||
@@ -32,3 +32,3 @@ } | ||
**/ | ||
// async downloadData(socket, data, roomInfo) { | ||
// async downloadData(socket, data, socketInfo) { | ||
// const export_type = data.type || "json"; | ||
@@ -39,3 +39,3 @@ | ||
// const result = data.data; | ||
// const orgId = roomInfo ? roomInfo.orgId : ""; | ||
// const orgId = socketInfo ? socketInfo.orgId : ""; | ||
// if (export_type === 'csv') { | ||
@@ -66,3 +66,3 @@ // binaryData = await json2csv.json2csvAsync(JSON.parse(JSON.stringify(result)), { | ||
**/ | ||
// async exportData(socket, data, roomInfo) { | ||
// async exportData(socket, data, socketInfo) { | ||
// const self = this; | ||
@@ -75,3 +75,3 @@ | ||
// var collection = this.dbClient.db(data['namespace']).collection(data["collection"]); | ||
// const orgId = roomInfo ? roomInfo.orgId : ""; | ||
// const orgId = socketInfo ? socketInfo.orgId : ""; | ||
@@ -100,3 +100,3 @@ // var query = {}; | ||
// async setImportData(socket, data, roomInfo) { | ||
// async setImportData(socket, data, socketInfo) { | ||
// this.importCollection = data['collection'] | ||
@@ -107,3 +107,3 @@ // this.importType = data['import_type']; | ||
// async importData(socket, data, roomInfo) { | ||
// async importData(socket, data, socketInfo) { | ||
// const importCollection = data['collection'] | ||
@@ -116,3 +116,3 @@ // const importType = data['import_type']; | ||
// const self = this; | ||
// // const orgId = roomInfo ? roomInfo.orgId : ""; | ||
// // const orgId = socketInfo ? socketInfo.orgId : ""; | ||
// if (!importCollection || !importType) { | ||
@@ -119,0 +119,0 @@ // return; |
@@ -14,6 +14,6 @@ const {ObjectID} = require("mongodb"); | ||
if (this.wsManager) { | ||
this.wsManager.on('createDocument', (socket, data, roomInfo) => this.createDocument(socket, data, roomInfo)); | ||
this.wsManager.on('readDocument', (socket, data, roomInfo) => this.readDocument(socket, data, roomInfo)) | ||
this.wsManager.on('updateDocument', (socket, data, roomInfo) => this.updateDocument(socket, data, roomInfo)) | ||
this.wsManager.on('deleteDocument', (socket, data, roomInfo) => this.deleteDocument(socket, data, roomInfo)) | ||
this.wsManager.on('createDocument', (socket, data, socketInfo) => this.createDocument(socket, data, socketInfo)); | ||
this.wsManager.on('readDocument', (socket, data, socketInfo) => this.readDocument(socket, data, socketInfo)) | ||
this.wsManager.on('updateDocument', (socket, data, socketInfo) => this.updateDocument(socket, data, socketInfo)) | ||
this.wsManager.on('deleteDocument', (socket, data, socketInfo) => this.deleteDocument(socket, data, socketInfo)) | ||
} | ||
@@ -23,3 +23,3 @@ } | ||
/** Create Document **/ | ||
async createDocument(socket, req_data, roomInfo){ | ||
async createDocument(socket, req_data, socketInfo){ | ||
const self = this; | ||
@@ -39,5 +39,5 @@ if(!req_data.data) return; | ||
// const response_data = response; | ||
self.broadcast('createDocument', socket, req_data, response, roomInfo) | ||
self.broadcast('createDocument', socket, response, socketInfo) | ||
} else { | ||
self.wsManager.send(socket, 'ServerError', error, null, roomInfo); | ||
self.wsManager.send(socket, 'ServerError', error, null, socketInfo); | ||
} | ||
@@ -47,3 +47,3 @@ }); | ||
console.log('createDocument error', error); | ||
self.wsManager.send(socket, 'ServerError', 'error', null, roomInfo); | ||
self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo); | ||
} | ||
@@ -53,5 +53,5 @@ } | ||
/** Read Document **/ | ||
async readDocument(socket, req_data, roomInfo) { | ||
async readDocument(socket, req_data, socketInfo) { | ||
if (!req_data['collection'] || req_data['collection'] == 'null' || typeof req_data['collection'] !== 'string') { | ||
this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo); | ||
this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo); | ||
return; | ||
@@ -89,5 +89,5 @@ } | ||
let isFlat = req_data.isFlat == true ? true : false; | ||
self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], roomInfo); | ||
self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], socketInfo); | ||
} else { | ||
self.wsManager.send(socket, 'ServerError', error, null, roomInfo); | ||
self.wsManager.send(socket, 'ServerError', error, null, socketInfo); | ||
} | ||
@@ -97,3 +97,3 @@ }); | ||
console.log('readDocument error', error); | ||
self.wsManager.send(socket, 'ServerError', 'error', null, roomInfo); | ||
self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo); | ||
} | ||
@@ -103,3 +103,3 @@ } | ||
/** Update Document **/ | ||
async updateDocument(socket, req_data, roomInfo) { | ||
async updateDocument(socket, req_data, socketInfo) { | ||
const self = this; | ||
@@ -143,6 +143,6 @@ try { | ||
self.broadcast('updateDocument', socket, req_data, response, roomInfo) | ||
self.broadcast('updateDocument', socket, response, socketInfo) | ||
}).catch((error) => { | ||
console.log('error', error) | ||
self.wsManager.send(socket, 'ServerError', error, null, roomInfo); | ||
self.wsManager.send(socket, 'ServerError', error, null, socketInfo); | ||
}); | ||
@@ -157,3 +157,3 @@ | ||
/** Delete Document **/ | ||
async deleteDocument(socket, req_data, roomInfo) { | ||
async deleteDocument(socket, req_data, socketInfo) { | ||
const self = this; | ||
@@ -171,5 +171,5 @@ | ||
let response = { ...req_data } | ||
self.broadcast('deleteDocument', socket, req_data, response, roomInfo) | ||
self.broadcast('deleteDocument', socket, response, socketInfo) | ||
} else { | ||
self.wsManager.send(socket, 'ServerError', error, null, roomInfo); | ||
self.wsManager.send(socket, 'ServerError', error, null, socketInfo); | ||
} | ||
@@ -179,18 +179,8 @@ }) | ||
console.log(error); | ||
self.wsManager.send(socket, 'ServerError', 'error', null, roomInfo); | ||
self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo); | ||
} | ||
} | ||
broadcast(component, socket, req_data, response, roomInfo) { | ||
if (req_data.broadcast_sender != false) { | ||
this.wsManager.send(socket, component, { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo); | ||
} | ||
if (req_data.broadcast !== false) { | ||
if (req_data.room) { | ||
this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, component, response, true, roomInfo); | ||
} else { | ||
this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, component, response, true, roomInfo) | ||
} | ||
} | ||
broadcast(component, socket, response, socketInfo) { | ||
this.wsManager.broadcast(socket, response.namespace || response['organization_id'], response.room, component, response, socketInfo); | ||
process.emit('changed-document', response) | ||
@@ -197,0 +187,0 @@ } |
@@ -11,4 +11,4 @@ const {ObjectID} = require("mongodb"); | ||
init() { | ||
this.wsManager.on('readDocumentList', (socket, data, roomInfo) => this.readDocumentList(socket, data, roomInfo)); | ||
this.wsManager.on('readCollectionList', (socket, data, roomInfo) => this.readCollectionList(socket, data, roomInfo)); | ||
this.wsManager.on('readDocumentList', (socket, data, socketInfo) => this.readDocumentList(socket, data, socketInfo)); | ||
this.wsManager.on('readCollectionList', (socket, data, socketInfo) => this.readCollectionList(socket, data, socketInfo)); | ||
} | ||
@@ -51,3 +51,3 @@ | ||
**/ | ||
async readDocumentList(socket, req_data, roomInfo) { | ||
async readDocumentList(socket, req_data, socketInfo) { | ||
function sleep(ms) { | ||
@@ -64,3 +64,3 @@ return new Promise((resolve) => { | ||
if (req_data['is_collection']) { | ||
var result = await this.readCollectionList(socket, req_data, roomInfo); | ||
var result = await this.readCollectionList(socket, req_data, socketInfo); | ||
return; | ||
@@ -122,6 +122,6 @@ } | ||
} | ||
self.wsManager.send(socket, 'readDocumentList', { ...req_data, data: result_data, operator: {...operator, total: total}}, req_data['organization_id'], roomInfo); | ||
self.wsManager.send(socket, 'readDocumentList', { ...req_data, data: result_data, operator: {...operator, total: total}}, req_data['organization_id'], socketInfo); | ||
} else { | ||
console.log(error) | ||
self.wsManager.send(socket, 'ServerError', error, null, roomInfo); | ||
self.wsManager.send(socket, 'ServerError', error, null, socketInfo); | ||
} | ||
@@ -131,7 +131,7 @@ }) | ||
console.log('readDocumentList error', error); | ||
this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo); | ||
this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo); | ||
} | ||
} | ||
async readCollectionList(socket, data, roomInfo) { | ||
async readCollectionList(socket, data, socketInfo) { | ||
try { | ||
@@ -153,5 +153,5 @@ var collections = []; | ||
this.wsManager.send(socket, 'readCollectionList', {...data, data: collections }, data['organization_id'], roomInfo); | ||
this.wsManager.send(socket, 'readCollectionList', {...data, data: collections }, data['organization_id'], socketInfo); | ||
} catch(error) { | ||
this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo); | ||
this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo); | ||
} | ||
@@ -158,0 +158,0 @@ } |
80283
747