@cocreate/crud-server 1.3.4 → 1.4.2
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 +22 -0
- package/CoCreate.config.js +1 -1
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/crud.js +14 -7
- package/src/list.js +13 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [1.4.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.4.1...v1.4.2) (2022-05-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* createDocument requires organization_id to be stored ([259f56d](https://github.com/CoCreate-app/CoCreate-crud-server/commit/259f56daadc6b9e148f054c0ba2cf04443122a6a))
|
|
7
|
+
|
|
8
|
+
## [1.4.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.4.0...v1.4.1) (2022-05-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* replace ObjectID with ObjectId due to mongodb depreciation ([93e4294](https://github.com/CoCreate-app/CoCreate-crud-server/commit/93e42944447357ec6a244b72ce968bbd8ff5c93d))
|
|
14
|
+
* update config organization_Id to organization_id ([996611b](https://github.com/CoCreate-app/CoCreate-crud-server/commit/996611baf2b2d3afbf895ef193ae15ba7226e77a))
|
|
15
|
+
|
|
16
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.4...v1.4.0) (2022-04-01)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* readCollections to return a list of collections ([2ad15d4](https://github.com/CoCreate-app/CoCreate-crud-server/commit/2ad15d43baf22c6dabbf56582cac182dec8876ad))
|
|
22
|
+
|
|
1
23
|
## [1.3.4](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.3...v1.3.4) (2022-03-06)
|
|
2
24
|
|
|
3
25
|
|
package/CoCreate.config.js
CHANGED
package/docs/index.html
CHANGED
package/package.json
CHANGED
package/src/crud.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {ObjectId} = require("mongodb");
|
|
2
2
|
const {encodeObject, replaceArray} = require("./utils.crud.js")
|
|
3
3
|
|
|
4
4
|
|
|
@@ -22,15 +22,16 @@ class CoCreateCrud {
|
|
|
22
22
|
async createDocument(socket, req_data, socketInfo){
|
|
23
23
|
const self = this;
|
|
24
24
|
if(!req_data.data) return;
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
try{
|
|
27
27
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
28
28
|
const collection = db.collection(req_data["collection"]);
|
|
29
29
|
let insertData = replaceArray(req_data.data);
|
|
30
|
+
insertData['organization_id'] = req_data['organization_id'];
|
|
30
31
|
|
|
31
32
|
collection.insertOne(insertData, function(error, result) {
|
|
32
33
|
if(!error && result){
|
|
33
|
-
const response = {...req_data, document_id: result.
|
|
34
|
+
const response = {...req_data, document_id: `${result.insertedId}`, data: insertData }
|
|
34
35
|
// let isFlat = req_data.isFlat == false ? false : true;
|
|
35
36
|
// const response_data = isFlat ? encodeObject(response) : response;
|
|
36
37
|
// const response_data = response;
|
|
@@ -58,13 +59,18 @@ class CoCreateCrud {
|
|
|
58
59
|
const collection = db.collection(req_data["collection"]);
|
|
59
60
|
|
|
60
61
|
const query = {
|
|
61
|
-
"_id": new
|
|
62
|
+
"_id": new ObjectId(req_data["document_id"])
|
|
62
63
|
};
|
|
63
64
|
if (req_data['organization_id']) {
|
|
64
65
|
query['organization_id'] = req_data['organization_id'];
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
collection.find(query).toArray(function(error, result) {
|
|
69
|
+
if (req_data["collection"] == 'test') {
|
|
70
|
+
console.log('query', query)
|
|
71
|
+
console.log('readDocument request', req_data)
|
|
72
|
+
console.log('readDocument result', result)
|
|
73
|
+
}
|
|
68
74
|
if (!error && result && result.length > 0) {
|
|
69
75
|
let tmp = result[0];
|
|
70
76
|
if (req_data['exclude_fields']) {
|
|
@@ -83,6 +89,7 @@ class CoCreateCrud {
|
|
|
83
89
|
let isFlat = req_data.isFlat == true ? true : false;
|
|
84
90
|
self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], socketInfo);
|
|
85
91
|
} else {
|
|
92
|
+
console.log('readDocument error', error)
|
|
86
93
|
self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
|
|
87
94
|
}
|
|
88
95
|
});
|
|
@@ -98,10 +105,10 @@ class CoCreateCrud {
|
|
|
98
105
|
try {
|
|
99
106
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
100
107
|
const collection = db.collection(req_data["collection"]);
|
|
101
|
-
let objId = new
|
|
108
|
+
let objId = new ObjectId();
|
|
102
109
|
try {
|
|
103
110
|
if (req_data["document_id"]) {
|
|
104
|
-
objId = new
|
|
111
|
+
objId = new ObjectId(req_data["document_id"]);
|
|
105
112
|
}
|
|
106
113
|
} catch (err) {
|
|
107
114
|
console.log(err);
|
|
@@ -152,7 +159,7 @@ class CoCreateCrud {
|
|
|
152
159
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
153
160
|
const collection = db.collection(req_data["collection"]);
|
|
154
161
|
const query = {
|
|
155
|
-
"_id": new
|
|
162
|
+
"_id": new ObjectId(req_data["document_id"])
|
|
156
163
|
};
|
|
157
164
|
|
|
158
165
|
collection.deleteOne(query, function(error, result) {
|
package/src/list.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {ObjectId} = require("mongodb");
|
|
2
2
|
|
|
3
3
|
class CoCreateList {
|
|
4
4
|
constructor(wsManager, dbClient) {
|
|
@@ -9,7 +9,7 @@ class CoCreateList {
|
|
|
9
9
|
|
|
10
10
|
init() {
|
|
11
11
|
this.wsManager.on('readDocumentList', (socket, data, socketInfo) => this.readDocumentList(socket, data, socketInfo));
|
|
12
|
-
this.wsManager.on('
|
|
12
|
+
this.wsManager.on('readCollections', (socket, data, socketInfo) => this.readCollections(socket, data, socketInfo));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -40,7 +40,6 @@ class CoCreateList {
|
|
|
40
40
|
count: 0 (integer)
|
|
41
41
|
},
|
|
42
42
|
|
|
43
|
-
is_collection: true | false,
|
|
44
43
|
//. case fetch document case
|
|
45
44
|
export: true | false
|
|
46
45
|
-------- additional response data -----------
|
|
@@ -53,13 +52,11 @@ class CoCreateList {
|
|
|
53
52
|
setTimeout(resolve, ms);
|
|
54
53
|
});
|
|
55
54
|
}
|
|
56
|
-
|
|
57
|
-
// await sleep(3000)
|
|
58
55
|
|
|
59
56
|
const self = this;
|
|
60
57
|
|
|
61
58
|
if (req_data['is_collection']) {
|
|
62
|
-
var result = await this.
|
|
59
|
+
var result = await this.readCollections(socket, req_data, socketInfo);
|
|
63
60
|
return;
|
|
64
61
|
}
|
|
65
62
|
|
|
@@ -128,30 +125,21 @@ class CoCreateList {
|
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
127
|
|
|
131
|
-
async
|
|
128
|
+
async readCollections(socket, data, socketInfo) {
|
|
132
129
|
try {
|
|
133
|
-
|
|
134
|
-
const db = this.dbClient.db(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
name: item.name,
|
|
141
|
-
_id: __uuid,
|
|
142
|
-
id: __uuid,
|
|
143
|
-
});
|
|
144
|
-
})
|
|
145
|
-
return result;
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
this.wsManager.send(socket, 'readCollectionList', {...data, data: collections }, data['organization_id'], socketInfo);
|
|
130
|
+
const self = this;
|
|
131
|
+
const db = this.dbClient.db(data['organization_id']);
|
|
132
|
+
db.listCollections().toArray(function(error, result) {
|
|
133
|
+
if (!error && result && result.length > 0) {
|
|
134
|
+
self.wsManager.send(socket, 'readCollections', {...data, data: result }, data['organization_id'], socketInfo);
|
|
135
|
+
}
|
|
136
|
+
})
|
|
149
137
|
} catch(error) {
|
|
138
|
+
console.log('readCollections error', error);
|
|
150
139
|
this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
|
|
151
140
|
}
|
|
152
141
|
}
|
|
153
142
|
|
|
154
|
-
|
|
155
143
|
/**
|
|
156
144
|
* function that make query from data
|
|
157
145
|
*
|
|
@@ -170,7 +158,7 @@ class CoCreateList {
|
|
|
170
158
|
query[key] = {};
|
|
171
159
|
}
|
|
172
160
|
|
|
173
|
-
if (item.name == "_id") item.value = item.value.map(v => new
|
|
161
|
+
if (item.name == "_id") item.value = item.value.map(v => new ObjectId(v))
|
|
174
162
|
|
|
175
163
|
switch (item.operator) {
|
|
176
164
|
case '$contain':
|