@cocreate/crud-server 1.2.9 → 1.3.1
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 +27 -0
- package/package.json +3 -3
- package/src/backup.js +7 -30
- package/src/crud.js +42 -123
- package/src/index.js +11 -0
- package/src/list.js +12 -107
- package/index.js +0 -19
- package/src/base.js +0 -86
- package/src/industry.js +0 -324
- package/src/organization.js +0 -112
- package/src/unique.js +0 -54
- package/src/user.js +0 -284
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
## [1.3.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.0...v1.3.1) (2022-03-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* bump version ([3b7adce](https://github.com/CoCreate-app/CoCreate-crud-server/commit/3b7adcef74cf426dc34d723478c44360a6f28219))
|
|
7
|
+
|
|
8
|
+
# [1.3.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.2.10...v1.3.0) (2022-03-03)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* moved files to there relative components ([a2b2f8c](https://github.com/CoCreate-app/CoCreate-crud-server/commit/a2b2f8c52a923cb4fad86331ff7121b19db3d527))
|
|
14
|
+
* remove securityCheck function, it has be replaced by permissions ([818b8d2](https://github.com/CoCreate-app/CoCreate-crud-server/commit/818b8d2e8631027242930633090510b579ecc914))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* deleteIndustry function ([ee85ff2](https://github.com/CoCreate-app/CoCreate-crud-server/commit/ee85ff2c09781159c4aa4950f209d785c32fcbab))
|
|
20
|
+
|
|
21
|
+
## [1.2.10](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.2.9...v1.2.10) (2022-02-28)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* moved index.js to src/ ([fdeb6c4](https://github.com/CoCreate-app/CoCreate-crud-server/commit/fdeb6c4a4ba4cc201e935268ad9d1feccdd4fbac))
|
|
27
|
+
|
|
1
28
|
## [1.2.9](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.2.8...v1.2.9) (2022-02-28)
|
|
2
29
|
|
|
3
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/crud-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "CoCreate-crud-server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cocreate-crud",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
29
29
|
"docs": "node ./node_modules/@cocreate/docs/src/index.js"
|
|
30
30
|
},
|
|
31
|
-
"main": "index
|
|
31
|
+
"main": "./src/index",
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
34
|
"url": "git+https://github.com/CoCreate-app/CoCreate-crud-server.git"
|
|
@@ -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.
|
|
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
|
|
8
|
-
constructor(wsManager,
|
|
9
|
-
|
|
10
|
-
this.
|
|
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.
|
|
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.
|
|
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,31 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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',
|
|
16
|
-
this.wsManager.on('readDocument',
|
|
17
|
-
this.wsManager.on('updateDocument',
|
|
18
|
-
this.wsManager.on('deleteDocument',
|
|
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
|
-
const self = this;
|
|
56
23
|
if(!req_data.data) return;
|
|
57
24
|
|
|
58
25
|
try{
|
|
59
|
-
const
|
|
26
|
+
const db = this.dbClient.db(req_data['organization_id']);
|
|
27
|
+
const collection = db.collection(req_data["collection"]);
|
|
60
28
|
let insertData = replaceArray(req_data.data);
|
|
61
|
-
// if (!insertData.organization_id) {
|
|
62
|
-
// insertData.organization_id = req_data.organization_id;
|
|
63
|
-
// }
|
|
64
29
|
|
|
65
30
|
collection.insertOne(insertData, function(error, result) {
|
|
66
31
|
if(!error && result){
|
|
@@ -68,29 +33,9 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
68
33
|
// let isFlat = req_data.isFlat == false ? false : true;
|
|
69
34
|
// const response_data = isFlat ? encodeObject(response) : response;
|
|
70
35
|
const response_data = response;
|
|
71
|
-
|
|
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
|
-
|
|
36
|
+
this.broadcast('createDocument', socket, req_data, reponse, roomInfo)
|
|
92
37
|
} else {
|
|
93
|
-
|
|
38
|
+
this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
94
39
|
}
|
|
95
40
|
});
|
|
96
41
|
}catch(error){
|
|
@@ -105,11 +50,10 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
105
50
|
this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
|
|
106
51
|
return;
|
|
107
52
|
}
|
|
108
|
-
const self = this;
|
|
109
53
|
|
|
110
54
|
try {
|
|
111
|
-
|
|
112
|
-
const collection =
|
|
55
|
+
const db = this.dbClient.db(req_data['organization_id']);
|
|
56
|
+
const collection = db.collection(req_data["collection"]);
|
|
113
57
|
|
|
114
58
|
const query = {
|
|
115
59
|
"_id": new ObjectID(req_data["document_id"])
|
|
@@ -127,7 +71,6 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
127
71
|
})
|
|
128
72
|
}
|
|
129
73
|
|
|
130
|
-
|
|
131
74
|
if (req_data.data) {
|
|
132
75
|
let resp = {};
|
|
133
76
|
resp['_id'] = tmp['_id']
|
|
@@ -136,9 +79,9 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
136
79
|
}
|
|
137
80
|
|
|
138
81
|
let isFlat = req_data.isFlat == true ? true : false;
|
|
139
|
-
|
|
82
|
+
this.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], roomInfo);
|
|
140
83
|
} else {
|
|
141
|
-
|
|
84
|
+
this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
142
85
|
}
|
|
143
86
|
});
|
|
144
87
|
} catch (error) {
|
|
@@ -149,11 +92,9 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
149
92
|
|
|
150
93
|
/** Update Document **/
|
|
151
94
|
async updateDocument(socket, req_data, roomInfo) {
|
|
152
|
-
const self = this;
|
|
153
|
-
|
|
154
95
|
try {
|
|
155
|
-
|
|
156
|
-
const collection =
|
|
96
|
+
const db = this.dbClient.db(req_data['organization_id']);
|
|
97
|
+
const collection = db.collection(req_data["collection"]);
|
|
157
98
|
let objId = new ObjectID();
|
|
158
99
|
try {
|
|
159
100
|
if (req_data["document_id"]) {
|
|
@@ -163,7 +104,6 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
163
104
|
console.log(err);
|
|
164
105
|
}
|
|
165
106
|
const query = {"_id": objId };
|
|
166
|
-
|
|
167
107
|
const update = {};
|
|
168
108
|
|
|
169
109
|
|
|
@@ -176,16 +116,12 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
176
116
|
projection[x] = 1
|
|
177
117
|
})
|
|
178
118
|
|
|
179
|
-
collection.findOneAndUpdate(
|
|
180
|
-
query,
|
|
181
|
-
update,
|
|
182
|
-
{
|
|
119
|
+
collection.findOneAndUpdate( query, update, {
|
|
183
120
|
returnOriginal : false,
|
|
184
121
|
upsert: req_data.upsert || false,
|
|
185
122
|
projection: projection,
|
|
186
123
|
}
|
|
187
124
|
).then((result) => {
|
|
188
|
-
|
|
189
125
|
let isFlat = req_data.isFlat == true ? true : false;
|
|
190
126
|
let response_data = result.value || {};
|
|
191
127
|
|
|
@@ -193,35 +129,23 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
193
129
|
|
|
194
130
|
if(req_data['unset']) response['delete_fields'] = req_data['unset'];
|
|
195
131
|
|
|
196
|
-
|
|
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);
|
|
132
|
+
this.broadcast('updateDocument', socket, req_data, response, roomInfo)
|
|
209
133
|
}).catch((error) => {
|
|
210
|
-
|
|
134
|
+
console.log('error', error)
|
|
135
|
+
this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
211
136
|
});
|
|
212
137
|
|
|
213
138
|
} catch (error) {
|
|
214
139
|
console.log(error)
|
|
215
|
-
|
|
140
|
+
this.wsManager.send(socket, 'updateDocumentError', error, req_data['organization_id']);
|
|
216
141
|
}
|
|
217
142
|
}
|
|
218
143
|
|
|
219
144
|
/** Delete Document **/
|
|
220
145
|
async deleteDocument(socket, req_data, roomInfo) {
|
|
221
|
-
const self = this;
|
|
222
|
-
|
|
223
146
|
try {
|
|
224
|
-
const
|
|
147
|
+
const db = this.dbClient.db(req_data['organization_id']);
|
|
148
|
+
const collection = db.collection(req_data["collection"]);
|
|
225
149
|
const query = {
|
|
226
150
|
"_id": new ObjectID(req_data["document_id"])
|
|
227
151
|
};
|
|
@@ -229,19 +153,9 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
229
153
|
collection.deleteOne(query, function(error, result) {
|
|
230
154
|
if (!error) {
|
|
231
155
|
let response = { ...req_data }
|
|
232
|
-
|
|
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);
|
|
156
|
+
this.broadcast('deleteDocument', socket, req_data, response, roomInfo)
|
|
243
157
|
} else {
|
|
244
|
-
|
|
158
|
+
this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
245
159
|
}
|
|
246
160
|
})
|
|
247
161
|
} catch (error) {
|
|
@@ -250,15 +164,20 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
250
164
|
}
|
|
251
165
|
}
|
|
252
166
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
167
|
+
broadcast(component, socket, req_data, response, roomInfo) {
|
|
168
|
+
if (req_data.broadcast_sender != false) {
|
|
169
|
+
this.wsManager.send(socket, component, { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (req_data.broadcast !== false) {
|
|
173
|
+
if (req_data.room) {
|
|
174
|
+
this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, component, response, true, roomInfo);
|
|
175
|
+
} else {
|
|
176
|
+
this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, component, response, true, roomInfo)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
process.emit('changed-document', response)
|
|
258
180
|
}
|
|
259
181
|
}
|
|
260
182
|
|
|
261
183
|
module.exports = CoCreateCrud;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
package/src/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const crud = require('./crud');
|
|
4
|
+
const list = require('./list');
|
|
5
|
+
const backup = require('./backup');
|
|
6
|
+
|
|
7
|
+
module.exports.init = function(wsManager, dbClient) {
|
|
8
|
+
new crud(wsManager, dbClient);
|
|
9
|
+
new list(wsManager, dbClient);
|
|
10
|
+
new backup(wsManager, dbClient);
|
|
11
|
+
}
|
package/src/list.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
+
const {ObjectID} = require("mongodb");
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
|
150
|
-
|
|
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:
|
|
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/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const crud = require('./src/crud');
|
|
4
|
-
const list = require('./src/list');
|
|
5
|
-
const user = require('./src/user');
|
|
6
|
-
const unique = require('./src/unique');
|
|
7
|
-
const organization = require('./src/organization.js');
|
|
8
|
-
const industry = require('./src/industry.js');
|
|
9
|
-
const backup = require('./src/backup');
|
|
10
|
-
|
|
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);
|
|
19
|
-
}
|