@cocreate/crud-server 1.2.10 → 1.3.0

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,16 @@
1
+ # [1.3.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.2.10...v1.3.0) (2022-03-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * moved files to there relative components ([a2b2f8c](https://github.com/CoCreate-app/CoCreate-crud-server/commit/a2b2f8c52a923cb4fad86331ff7121b19db3d527))
7
+ * remove securityCheck function, it has be replaced by permissions ([818b8d2](https://github.com/CoCreate-app/CoCreate-crud-server/commit/818b8d2e8631027242930633090510b579ecc914))
8
+
9
+
10
+ ### Features
11
+
12
+ * deleteIndustry function ([ee85ff2](https://github.com/CoCreate-app/CoCreate-crud-server/commit/ee85ff2c09781159c4aa4950f209d785c32fcbab))
13
+
1
14
  ## [1.2.10](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.2.9...v1.2.10) (2022-02-28)
2
15
 
3
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.2.10",
3
+ "version": "1.3.0",
4
4
  "description": "CoCreate-crud-server",
5
5
  "keywords": [
6
6
  "cocreate-crud",
@@ -43,7 +43,7 @@
43
43
  "@cocreate/docs": "^1.2.70",
44
44
  "csvtojson": "^2.0.10",
45
45
  "json-2-csv": "^3.10.3",
46
- "mongodb": "^4.1.4"
46
+ "mongodb": "^4.4.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "express": "^4.17.1"
package/src/backup.js CHANGED
@@ -1,17 +1,14 @@
1
-
2
- const CoCreateBase = require("./base");
3
-
4
1
  const json2csv = require("json-2-csv")
5
2
  const csvtojson = require("csvtojson");
6
3
 
7
- class CoCreateBackup extends CoCreateBase {
8
- constructor(wsManager, db) {
9
- super(wsManager, db);
10
- this.init();
11
-
4
+ class CoCreateBackup {
5
+ constructor(wsManager, dbClient) {
6
+ this.wsManager = wsManager
7
+ this.dbClient = dbClient
12
8
  this.importCollection = '';
13
9
  this.importType = '';
14
10
  this.importDB = '';
11
+ this.init();
15
12
  }
16
13
 
17
14
  init() {
@@ -64,24 +61,16 @@ class CoCreateBackup extends CoCreateBase {
64
61
  })
65
62
  **/
66
63
  // async exportData(socket, data, roomInfo) {
67
- // const securityRes = await this.checkSecurity(data);
68
- // if (!securityRes.result) {
69
- // this.wsManager.send(socket, 'securityError', 'error');
70
- // return;
71
- // }
72
64
  // const self = this;
73
65
 
74
66
  // const export_type = data.export_type || "json";
75
67
 
76
68
  // try {
77
69
 
78
- // var collection = this.getDb(data['namespace']).collection(data["collection"]);
70
+ // var collection = this.dbClient.db(data['namespace']).collection(data["collection"]);
79
71
  // const orgId = roomInfo ? roomInfo.orgId : "";
80
72
 
81
73
  // var query = {};
82
- // if (securityRes['organization_id']) {
83
- // query['organization_id'] = securityRes['organization_id'];
84
- // }
85
74
 
86
75
  // collection.find(query).toArray(async function(error, result) {
87
76
  // if (!error) {
@@ -104,24 +93,12 @@ class CoCreateBackup extends CoCreateBase {
104
93
  // }
105
94
 
106
95
  // async setImportData(socket, data, roomInfo) {
107
- // const securityRes = await this.checkSecurity(data);
108
- // const orgId = roomInfo ? roomInfo.orgId : "";
109
- // if (!securityRes.result) {
110
- // this.wsManager.send(socket, 'securityError', 'error', orgId);
111
- // return;
112
- // }
113
96
  // this.importCollection = data['collection']
114
97
  // this.importType = data['import_type'];
115
98
  // this.importDB = data['namespace'];
116
99
  // }
117
100
 
118
101
  // async importData(socket, data, roomInfo) {
119
- // const securityRes = await this.checkSecurity(data);
120
- // const orgId = roomInfo ? roomInfo.orgId : "";
121
- // if (!securityRes.result) {
122
- // this.wsManager.send(socket, 'securityError', 'error', orgId);
123
- // return;
124
- // }
125
102
  // const importCollection = data['collection']
126
103
  // const importType = data['import_type'];
127
104
  // const importFile = data['file'];
@@ -146,7 +123,7 @@ class CoCreateBackup extends CoCreateBase {
146
123
  // // todo: validate json / if json is object error happens
147
124
  // jsonData.map((item) => delete item._id);
148
125
  // console.log('json: ', jsonData)
149
- // var collection = this.getDb(orgId).collection(importCollection);
126
+ // var collection = this.dbClient.db(orgId).collection(importCollection);
150
127
  // // console.log(this.importCollection)
151
128
  // collection.insertMany(jsonData, function(err, result) {
152
129
  // if (!err) {
package/src/crud.js CHANGED
@@ -1,66 +1,32 @@
1
+ const {ObjectID} = require("mongodb");
2
+ const {encodeObject, replaceArray} = require("./utils.crud.js")
1
3
 
2
- const {ObjectID, Binary} = require("mongodb");
3
- const CoCreateBase = require("./base");
4
- const {encodeObject, decodeObject, replaceArray} = require("./utils.crud.js")
5
4
 
6
-
7
- class CoCreateCrud extends CoCreateBase {
8
- constructor(wsManager, db) {
9
- super(wsManager, db);
5
+ class CoCreateCrud {
6
+ constructor(wsManager, dbClient) {
7
+ this.wsManager = wsManager
8
+ this.dbClient = dbClient
10
9
  this.init();
11
10
  }
12
11
 
13
12
  init() {
14
13
  if (this.wsManager) {
15
- this.wsManager.on('createDocument', (socket, data, roomInfo) => this.createDocument(socket, data, roomInfo));
16
- this.wsManager.on('readDocument', (socket, data, roomInfo) => this.readDocument(socket, data, roomInfo))
17
- this.wsManager.on('updateDocument', (socket, data, roomInfo) => this.updateDocument(socket, data, roomInfo))
18
- this.wsManager.on('deleteDocument', (socket, data, roomInfo) => this.deleteDocument(socket, data, roomInfo))
14
+ this.wsManager.on('createDocument', (socket, data, roomInfo) => this.createDocument(socket, data, roomInfo));
15
+ this.wsManager.on('readDocument', (socket, data, roomInfo) => this.readDocument(socket, data, roomInfo))
16
+ this.wsManager.on('updateDocument', (socket, data, roomInfo) => this.updateDocument(socket, data, roomInfo))
17
+ this.wsManager.on('deleteDocument', (socket, data, roomInfo) => this.deleteDocument(socket, data, roomInfo))
19
18
  }
20
19
  }
21
20
 
22
- /** Create Document **/
23
- /*
24
- that.wsManager.onMessage(socket, "createDocument", data, roomInfo)
25
-
26
- that.wsManager.onMessage(socket, "readDocument", data, roomInfo)
27
-
28
- that.wsManager.onMessage(socket, "updateDocument", data, roomInfo)
29
- Example:
30
- that.wsManager.onMessage(socket, "updateDocument", {
31
- namespace: '',
32
- room: '',
33
- broadcast: true/false,
34
- broadcast_sender: true/false,
35
-
36
- collection: "test123",
37
- document_id: "document_id",
38
- data:{
39
-
40
- name1:“hello”,
41
- name2: “hello1”
42
- },
43
- delete_fields:["name3", "name4"],
44
- element: “xxxx”,
45
- metaData: "xxxx"
46
- }, roomInfo)
47
-
48
- that.wsManager.onMessage(socket, "deleteDocument", data, roomInfo)
49
- */
50
-
51
21
  /** Create Document **/
52
- // data param needs organization_id field added to pass security check
53
22
  async createDocument(socket, req_data, roomInfo){
54
-
55
23
  const self = this;
56
24
  if(!req_data.data) return;
57
25
 
58
26
  try{
59
- const collection = this.db.collection(req_data['collection']);
27
+ const db = this.dbClient.db(req_data['organization_id']);
28
+ const collection = db.collection(req_data["collection"]);
60
29
  let insertData = replaceArray(req_data.data);
61
- // if (!insertData.organization_id) {
62
- // insertData.organization_id = req_data.organization_id;
63
- // }
64
30
 
65
31
  collection.insertOne(insertData, function(error, result) {
66
32
  if(!error && result){
@@ -68,27 +34,7 @@ class CoCreateCrud extends CoCreateBase {
68
34
  // let isFlat = req_data.isFlat == false ? false : true;
69
35
  // const response_data = isFlat ? encodeObject(response) : response;
70
36
  const response_data = response;
71
- // console.log('createDocument response:', response)
72
-
73
-
74
- if (req_data.broadcast_sender != false) {
75
- self.wsManager.send(socket, 'createDocument', response, req_data['organization_id'], roomInfo);
76
- // console.log('broadcast1' , response)
77
- }
78
-
79
- if (req_data.broadcast != false) {
80
- if (req_data.room) {
81
- self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, 'createDocument', response_data, true, roomInfo);
82
- // console.log('broadcast2' ,response)
83
-
84
- } else {
85
- self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, 'createDocument', response_data, true, roomInfo)
86
- // console.log('broadcast3' ,response)
87
- }
88
- }
89
-
90
- self.processCRUDEvent('createDocument', response);
91
-
37
+ self.broadcast('createDocument', socket, req_data, roomInfo)
92
38
  } else {
93
39
  self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
94
40
  }
@@ -108,8 +54,8 @@ class CoCreateCrud extends CoCreateBase {
108
54
  const self = this;
109
55
 
110
56
  try {
111
-
112
- const collection = this.db.collection(req_data["collection"]);
57
+ const db = this.dbClient.db(req_data['organization_id']);
58
+ const collection = db.collection(req_data["collection"]);
113
59
 
114
60
  const query = {
115
61
  "_id": new ObjectID(req_data["document_id"])
@@ -127,7 +73,6 @@ class CoCreateCrud extends CoCreateBase {
127
73
  })
128
74
  }
129
75
 
130
-
131
76
  if (req_data.data) {
132
77
  let resp = {};
133
78
  resp['_id'] = tmp['_id']
@@ -152,8 +97,8 @@ class CoCreateCrud extends CoCreateBase {
152
97
  const self = this;
153
98
 
154
99
  try {
155
-
156
- const collection = this.db.collection(req_data["collection"]);
100
+ const db = this.dbClient.db(req_data['organization_id']);
101
+ const collection = db.collection(req_data["collection"]);
157
102
  let objId = new ObjectID();
158
103
  try {
159
104
  if (req_data["document_id"]) {
@@ -176,10 +121,7 @@ class CoCreateCrud extends CoCreateBase {
176
121
  projection[x] = 1
177
122
  })
178
123
 
179
- collection.findOneAndUpdate(
180
- query,
181
- update,
182
- {
124
+ collection.findOneAndUpdate( query, update, {
183
125
  returnOriginal : false,
184
126
  upsert: req_data.upsert || false,
185
127
  projection: projection,
@@ -193,19 +135,7 @@ class CoCreateCrud extends CoCreateBase {
193
135
 
194
136
  if(req_data['unset']) response['delete_fields'] = req_data['unset'];
195
137
 
196
- if (req_data.broadcast_sender != false) {
197
- self.wsManager.send(socket, 'updateDocument', { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo);
198
- }
199
-
200
- if (req_data.broadcast !== false) {
201
- if (req_data.room) {
202
- self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, 'updateDocument', response, true, roomInfo);
203
- } else {
204
- self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, 'updateDocument', response, true, roomInfo)
205
- }
206
- }
207
-
208
- self.processCRUDEvent('updateDocument', response);
138
+ self.broadcast('updateDocument', socket, req_data, roomInfo)
209
139
  }).catch((error) => {
210
140
  self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
211
141
  });
@@ -221,7 +151,8 @@ class CoCreateCrud extends CoCreateBase {
221
151
  const self = this;
222
152
 
223
153
  try {
224
- const collection = this.db.collection(req_data["collection"]);
154
+ const db = this.dbClient.db(req_data['organization_id']);
155
+ const collection = db.collection(req_data["collection"]);
225
156
  const query = {
226
157
  "_id": new ObjectID(req_data["document_id"])
227
158
  };
@@ -229,17 +160,7 @@ class CoCreateCrud extends CoCreateBase {
229
160
  collection.deleteOne(query, function(error, result) {
230
161
  if (!error) {
231
162
  let response = { ...req_data }
232
- if (req_data.broadcast_sender != false) {
233
- self.wsManager.send(socket, 'deleteDocument', { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo);
234
- }
235
- if (req_data.broadcast !== false) {
236
- if (req_data.room) {
237
- self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, 'deleteDocument', response, true, roomInfo);
238
- } else {
239
- self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, 'deleteDocument', response, true, roomInfo)
240
- }
241
- }
242
- self.processCRUDEvent('deleteDocument', response);
163
+ self.broadcast('deleteDocument', socket, req_data, roomInfo)
243
164
  } else {
244
165
  self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
245
166
  }
@@ -250,15 +171,20 @@ class CoCreateCrud extends CoCreateBase {
250
171
  }
251
172
  }
252
173
 
253
- processCRUDEvent(action, data) {
254
- process.emit('changed-document', data)
255
- // if (data.collection == 'permissions') {
256
- // process.emit('refresh-permission', data)
257
- // }
174
+ broadcast(component, socket, req_data, response, roomInfo) {
175
+ if (req_data.broadcast_sender != false) {
176
+ self.wsManager.send(socket, component, { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo);
177
+ }
178
+
179
+ if (req_data.broadcast !== false) {
180
+ if (req_data.room) {
181
+ self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, component, response, true, roomInfo);
182
+ } else {
183
+ self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, component, response, true, roomInfo)
184
+ }
185
+ }
186
+ process.emit('changed-document', response)
258
187
  }
259
188
  }
260
189
 
261
190
  module.exports = CoCreateCrud;
262
-
263
-
264
-
package/src/index.js CHANGED
@@ -2,18 +2,10 @@
2
2
 
3
3
  const crud = require('./crud');
4
4
  const list = require('./list');
5
- const user = require('./user');
6
- const unique = require('./unique');
7
- const organization = require('./organization');
8
- const industry = require('./industry');
9
5
  const backup = require('./backup');
10
6
 
11
- module.exports.init = function(socket_server, db_client) {
12
- new crud(socket_server, db_client);
13
- new list(socket_server, db_client);
14
- new user(socket_server, db_client);
15
- new unique(socket_server, db_client);
16
- new organization(socket_server, db_client);
17
- new industry(socket_server, db_client);
18
- new backup(socket_server, db_client);
7
+ module.exports.init = function(wsManager, dbClient) {
8
+ new crud(wsManager, dbClient);
9
+ new list(wsManager, dbClient);
10
+ new backup(wsManager, dbClient);
19
11
  }
package/src/list.js CHANGED
@@ -1,17 +1,15 @@
1
+ const {ObjectID} = require("mongodb");
1
2
 
2
- const CoCreateBase = require("./base");
3
- const {ObjectID, Binary} = require("mongodb");
4
-
5
- class CoCreateList extends CoCreateBase {
6
- constructor(wsManager, db) {
7
- super(wsManager, db);
3
+ class CoCreateList {
4
+ constructor(wsManager, dbClient) {
5
+ this.wsManager = wsManager
6
+ this.dbClient = dbClient
8
7
  this.init()
9
8
  }
10
9
 
11
10
  init() {
12
11
  this.wsManager.on('readDocumentList', (socket, data, roomInfo) => this.readDocumentList(socket, data, roomInfo));
13
12
  this.wsManager.on('readCollectionList', (socket, data, roomInfo) => this.readCollectionList(socket, data, roomInfo));
14
-
15
13
  }
16
14
 
17
15
  /**
@@ -49,9 +47,7 @@ class CoCreateList extends CoCreateBase {
49
47
  data: [] // array
50
48
  }
51
49
  **/
52
- async readDocumentList(socket, req_data, roomInfo) {
53
- // const securityRes = await this.checkSecurity(req_data);
54
-
50
+ async readDocumentList(socket, req_data, roomInfo) {
55
51
  function sleep(ms) {
56
52
  return new Promise((resolve) => {
57
53
  setTimeout(resolve, ms);
@@ -61,10 +57,6 @@ class CoCreateList extends CoCreateBase {
61
57
  // await sleep(3000)
62
58
 
63
59
  const self = this;
64
- // if (!securityRes.result) {
65
- // this.wsManager.send(socket, 'securityError', 'error', req_data['organization_id'], roomInfo);
66
- // return;
67
- // }
68
60
 
69
61
  if (req_data['is_collection']) {
70
62
  var result = await this.readCollectionList(socket, req_data, roomInfo);
@@ -72,7 +64,8 @@ class CoCreateList extends CoCreateBase {
72
64
  }
73
65
 
74
66
  try {
75
- var collection = this.db.collection(req_data['collection']);
67
+ const db = this.dbClient.db(req_data['organization_id']);
68
+ const collection = db.collection(req_data["collection"]);
76
69
  const operator = {
77
70
  filters: [],
78
71
  orders: [],
@@ -87,10 +80,6 @@ class CoCreateList extends CoCreateBase {
87
80
  var query = {};
88
81
  query = this.readQuery(operator);
89
82
 
90
- // if (securityRes['organization_id']) {
91
- // query['organization_id'] = securityRes['organization_id'];
92
- // }
93
-
94
83
  var sort = {};
95
84
  operator.orders.forEach((order) => {
96
85
  sort[order.name] = order.type
@@ -140,14 +129,10 @@ class CoCreateList extends CoCreateBase {
140
129
  }
141
130
 
142
131
  async readCollectionList(socket, data, roomInfo) {
143
- const securityRes = await this.checkSecurity(data);
144
- if (!securityRes.result) {
145
- this.wsManager.send(socket, 'securityError', 'error', data['organization_id'], roomInfo);
146
- return;
147
- }
148
132
  try {
149
- var result_collections = [];
150
- result_collections = await this.db.listCollections().toArray().then(infos => {
133
+ var collections = [];
134
+ const db = this.dbClient.db(req_data['organization_id']);
135
+ collections = await db.listCollections().toArray().then(infos => {
151
136
  var result = [];
152
137
  infos.forEach(function(item) {
153
138
  let __uuid = item.info.uuid.toString('hex')
@@ -160,92 +145,12 @@ class CoCreateList extends CoCreateBase {
160
145
  return result;
161
146
  })
162
147
 
163
- this.wsManager.send(socket, 'readCollectionList', {...data, data: result_collections }, data['organization_id'], roomInfo);
148
+ this.wsManager.send(socket, 'readCollectionList', {...data, data: collections }, data['organization_id'], roomInfo);
164
149
  } catch(error) {
165
150
  this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
166
151
  }
167
152
  }
168
153
 
169
- /**
170
- * fetch document by ids
171
- */
172
-
173
- // async function fetchDocumentList(socket, data) {
174
- // var securityRes = await checkSecurity(data);
175
- // if (!securityRes.result) {
176
- // socket.emit('securityError', 'error');
177
- // return;
178
- // }
179
-
180
- // try {
181
-
182
- // var collection = db.collection(data['collection']);
183
- // var query = {};
184
- // query = readQuery(data);
185
-
186
- // if (data['fetch'] && data.fetch.name) {
187
- // query[data.fetch.name] = data.fetch.value;
188
- // }
189
-
190
- // if (securityRes['organization_id']) {
191
- // query['organization_id'] = securityRes['organization_id'];
192
- // }
193
-
194
- // var sort = {};
195
- // data.orders.forEach((order) => {
196
- // sort[order.name] = order.type
197
- // });
198
-
199
- // collection.find(query).sort(sort).toArray(function(error, result) {
200
- // if (result) {
201
- // if (data['search']['type'] == 'and') {
202
- // result = readAndSearch(result, data['search']['value']);
203
- // } else {
204
- // result = readOrSearch(result, data['search']['value']);
205
- // }
206
-
207
- // var total = result.length;
208
- // var f_ids = data['fetch_ids'];
209
-
210
- // var _nn = result.length;
211
- // if (data['count']) {
212
- // _nn = data['startIndex'];
213
- // }
214
- // console.log(f_ids);
215
- // var ret_data = [];
216
- // for (let ii = 0; ii < _nn; ii++) {
217
-
218
- // for (let j = 0; j < f_ids.length; j++) {
219
-
220
- // console.log(f_ids[j], result[ii]['_id']);
221
- // if (f_ids[j] == result[ii]['_id']) {
222
-
223
- // ret_data.push({item: result[ii], position: ii});
224
-
225
- // }
226
- // }
227
- // }
228
-
229
- // console.log(ret_data);
230
-
231
- // socket.emit('fetchDocumentList', {
232
- // 'collection': data['collection'],
233
- // 'eId': data['eId'],
234
- // 'result': ret_data,
235
- // 'startIndex': data['startIndex'],
236
- // 'per_count': data['count'],
237
- // 'total': total,
238
- // 'options': data['options']
239
- // })
240
- // }
241
-
242
- // //console.log(error);
243
- // })
244
- // } catch (error) {
245
-
246
- // }
247
-
248
- // }
249
154
 
250
155
  /**
251
156
  * function that make query from data
package/src/base.js DELETED
@@ -1,86 +0,0 @@
1
-
2
- const {ObjectID} = require("mongodb");
3
-
4
- class CoCreateBase {
5
- constructor(wsManager, client) {
6
- this.wsManager = wsManager;
7
- this.db = client.db('mydb');
8
- this.dbClient = client;
9
-
10
- this.initBase()
11
-
12
- }
13
-
14
- initBase() {
15
- if (this.wsManager) {
16
- this.wsManager.on('changeDB', (socket, data, roomInfo) => this.changeDB(socket, data, roomInfo));
17
- }
18
- }
19
-
20
- /** Request available check **/
21
- async checkSecurity(data) {
22
-
23
- var apiKey = data['apiKey'];
24
- var organization_id = data['organization_id'];
25
-
26
- if (!apiKey || !organization_id) return {result: false};
27
-
28
- var collection = this.db.collection('organizations');
29
-
30
- try {
31
- var query = {
32
- "_id": new ObjectID(organization_id),
33
- "apiKey": data['apiKey'],
34
- }
35
-
36
- const result = await collection.find(query).toArray();
37
-
38
- if (result && result.length > 0) {
39
-
40
- if (data['collection'] == 'users' || data['collection'] == 'organizations') {
41
- return { result: true }
42
- } else {
43
- return { result: true, organization_id: data['organization_id'] }
44
- }
45
- }
46
- return {result: false};
47
- } catch (error) {
48
- console.log(error)
49
- }
50
- return {result: false};
51
- }
52
-
53
- changeDB(socket, data) {
54
- const dbName = data.db;
55
- if (!dbName) return;
56
- this.db = this.dbClient.db(dbName);
57
- return
58
- }
59
-
60
- getDB(namespace) {
61
- var dbConn;
62
- try {
63
- if (namespace && namespace != '') {
64
- dbConn = this.dbClient.db(namespace)
65
- } else {
66
- dbConn = this.dbClient.db('mydb');
67
- }
68
- } catch (error) {
69
- console.log(error)
70
- dbConn = this.dbClient.db('mydb');
71
- }
72
- return dbConn;
73
- }
74
-
75
- getCollection(data) {
76
- const collectionName = data['collection'];
77
- try {
78
- const dbName = data['db'] || data['organization_id'];
79
- return this.getDB(dbName).collection(collectionName);
80
- } catch (error) {
81
- return this.db.collection(collectionName);
82
- }
83
- }
84
- }
85
-
86
- module.exports = CoCreateBase;