@cocreate/crud-server 1.2.8 → 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 +29 -0
- package/CoCreate.config.js +1 -1
- package/package.json +3 -3
- package/src/backup.js +7 -30
- package/src/crud.js +41 -116
- 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,32 @@
|
|
|
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
|
+
|
|
14
|
+
## [1.2.10](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.2.9...v1.2.10) (2022-02-28)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* moved index.js to src/ ([fdeb6c4](https://github.com/CoCreate-app/CoCreate-crud-server/commit/fdeb6c4a4ba4cc201e935268ad9d1feccdd4fbac))
|
|
20
|
+
|
|
21
|
+
## [1.2.9](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.2.8...v1.2.9) (2022-02-28)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* config docs wildcard * domain ([c2a5856](https://github.com/CoCreate-app/CoCreate-crud-server/commit/c2a58569460e0fa45c594f6b70d7ade32e703ebb))
|
|
27
|
+
* update param is_flat to isFlat ([40a9b61](https://github.com/CoCreate-app/CoCreate-crud-server/commit/40a9b61408b5379aef3a798e1fdbc64016c3e980))
|
|
28
|
+
* updated is_flat to default false ([f0c2f00](https://github.com/CoCreate-app/CoCreate-crud-server/commit/f0c2f002c33ff8d0e1f3b306a2999cced5535936))
|
|
29
|
+
|
|
1
30
|
## [1.2.8](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.2.7...v1.2.8) (2022-02-16)
|
|
2
31
|
|
|
3
32
|
|
package/CoCreate.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/crud-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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,94 +1,40 @@
|
|
|
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
23
|
const self = this;
|
|
56
24
|
if(!req_data.data) return;
|
|
57
25
|
|
|
58
26
|
try{
|
|
59
|
-
const
|
|
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){
|
|
67
33
|
const response = {...req_data, document_id: result.ops[0]._id, data:result.ops[0] }
|
|
68
|
-
// let
|
|
69
|
-
// const response_data =
|
|
34
|
+
// let isFlat = req_data.isFlat == false ? false : true;
|
|
35
|
+
// const response_data = isFlat ? encodeObject(response) : response;
|
|
70
36
|
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
|
-
|
|
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 =
|
|
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']
|
|
@@ -135,9 +80,8 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
135
80
|
tmp = resp;
|
|
136
81
|
}
|
|
137
82
|
|
|
138
|
-
let
|
|
139
|
-
|
|
140
|
-
self.wsManager.send(socket, 'readDocument', { ...req_data, data: is_flat ? encodeObject(tmp) : tmp }, req_data['organization_id'], roomInfo);
|
|
83
|
+
let isFlat = req_data.isFlat == true ? true : false;
|
|
84
|
+
self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], roomInfo);
|
|
141
85
|
} else {
|
|
142
86
|
self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
143
87
|
}
|
|
@@ -153,8 +97,8 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
153
97
|
const self = this;
|
|
154
98
|
|
|
155
99
|
try {
|
|
156
|
-
|
|
157
|
-
const collection =
|
|
100
|
+
const db = this.dbClient.db(req_data['organization_id']);
|
|
101
|
+
const collection = db.collection(req_data["collection"]);
|
|
158
102
|
let objId = new ObjectID();
|
|
159
103
|
try {
|
|
160
104
|
if (req_data["document_id"]) {
|
|
@@ -177,36 +121,21 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
177
121
|
projection[x] = 1
|
|
178
122
|
})
|
|
179
123
|
|
|
180
|
-
collection.findOneAndUpdate(
|
|
181
|
-
query,
|
|
182
|
-
update,
|
|
183
|
-
{
|
|
124
|
+
collection.findOneAndUpdate( query, update, {
|
|
184
125
|
returnOriginal : false,
|
|
185
126
|
upsert: req_data.upsert || false,
|
|
186
127
|
projection: projection,
|
|
187
128
|
}
|
|
188
129
|
).then((result) => {
|
|
189
130
|
|
|
190
|
-
let
|
|
131
|
+
let isFlat = req_data.isFlat == true ? true : false;
|
|
191
132
|
let response_data = result.value || {};
|
|
192
133
|
|
|
193
|
-
let response = { ...req_data, document_id: response_data._id, data:
|
|
134
|
+
let response = { ...req_data, document_id: response_data._id, data: isFlat ? encodeObject(response_data) : response_data };
|
|
194
135
|
|
|
195
136
|
if(req_data['unset']) response['delete_fields'] = req_data['unset'];
|
|
196
137
|
|
|
197
|
-
|
|
198
|
-
self.wsManager.send(socket, 'updateDocument', { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (req_data.broadcast !== false) {
|
|
202
|
-
if (req_data.room) {
|
|
203
|
-
self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, 'updateDocument', response, true, roomInfo);
|
|
204
|
-
} else {
|
|
205
|
-
self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, 'updateDocument', response, true, roomInfo)
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
self.processCRUDEvent('updateDocument', response);
|
|
138
|
+
self.broadcast('updateDocument', socket, req_data, roomInfo)
|
|
210
139
|
}).catch((error) => {
|
|
211
140
|
self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
212
141
|
});
|
|
@@ -222,7 +151,8 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
222
151
|
const self = this;
|
|
223
152
|
|
|
224
153
|
try {
|
|
225
|
-
const
|
|
154
|
+
const db = this.dbClient.db(req_data['organization_id']);
|
|
155
|
+
const collection = db.collection(req_data["collection"]);
|
|
226
156
|
const query = {
|
|
227
157
|
"_id": new ObjectID(req_data["document_id"])
|
|
228
158
|
};
|
|
@@ -230,17 +160,7 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
230
160
|
collection.deleteOne(query, function(error, result) {
|
|
231
161
|
if (!error) {
|
|
232
162
|
let response = { ...req_data }
|
|
233
|
-
|
|
234
|
-
self.wsManager.send(socket, 'deleteDocument', { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo);
|
|
235
|
-
}
|
|
236
|
-
if (req_data.broadcast !== false) {
|
|
237
|
-
if (req_data.room) {
|
|
238
|
-
self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, 'deleteDocument', response, true, roomInfo);
|
|
239
|
-
} else {
|
|
240
|
-
self.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, 'deleteDocument', response, true, roomInfo)
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
self.processCRUDEvent('deleteDocument', response);
|
|
163
|
+
self.broadcast('deleteDocument', socket, req_data, roomInfo)
|
|
244
164
|
} else {
|
|
245
165
|
self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
246
166
|
}
|
|
@@ -251,15 +171,20 @@ class CoCreateCrud extends CoCreateBase {
|
|
|
251
171
|
}
|
|
252
172
|
}
|
|
253
173
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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)
|
|
259
187
|
}
|
|
260
188
|
}
|
|
261
189
|
|
|
262
190
|
module.exports = CoCreateCrud;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
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
|
-
}
|