@cocreate/crud-server 1.3.1 → 1.3.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 +7 -0
- package/package.json +1 -1
- package/src/crud.js +17 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.3.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.1...v1.3.2) (2022-03-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add self.wsManager ([537375e](https://github.com/CoCreate-app/CoCreate-crud-server/commit/537375ec182242ff012f0ed11a6d3fe5f905ff26))
|
|
7
|
+
|
|
1
8
|
## [1.3.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.0...v1.3.1) (2022-03-04)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/crud.js
CHANGED
|
@@ -20,6 +20,7 @@ class CoCreateCrud {
|
|
|
20
20
|
|
|
21
21
|
/** Create Document **/
|
|
22
22
|
async createDocument(socket, req_data, roomInfo){
|
|
23
|
+
const self = this;
|
|
23
24
|
if(!req_data.data) return;
|
|
24
25
|
|
|
25
26
|
try{
|
|
@@ -33,14 +34,14 @@ class CoCreateCrud {
|
|
|
33
34
|
// let isFlat = req_data.isFlat == false ? false : true;
|
|
34
35
|
// const response_data = isFlat ? encodeObject(response) : response;
|
|
35
36
|
const response_data = response;
|
|
36
|
-
|
|
37
|
+
self.broadcast('createDocument', socket, req_data, reponse, roomInfo)
|
|
37
38
|
} else {
|
|
38
|
-
|
|
39
|
+
self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
42
|
}catch(error){
|
|
42
43
|
console.log('createDocument error', error);
|
|
43
|
-
|
|
44
|
+
self.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
@@ -50,6 +51,7 @@ class CoCreateCrud {
|
|
|
50
51
|
this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
|
|
51
52
|
return;
|
|
52
53
|
}
|
|
54
|
+
const self = this;
|
|
53
55
|
|
|
54
56
|
try {
|
|
55
57
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
@@ -79,19 +81,20 @@ class CoCreateCrud {
|
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
let isFlat = req_data.isFlat == true ? true : false;
|
|
82
|
-
|
|
84
|
+
self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], roomInfo);
|
|
83
85
|
} else {
|
|
84
|
-
|
|
86
|
+
self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
85
87
|
}
|
|
86
88
|
});
|
|
87
89
|
} catch (error) {
|
|
88
90
|
console.log('readDocument error', error);
|
|
89
|
-
|
|
91
|
+
self.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
/** Update Document **/
|
|
94
96
|
async updateDocument(socket, req_data, roomInfo) {
|
|
97
|
+
const self = this;
|
|
95
98
|
try {
|
|
96
99
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
97
100
|
const collection = db.collection(req_data["collection"]);
|
|
@@ -129,20 +132,22 @@ class CoCreateCrud {
|
|
|
129
132
|
|
|
130
133
|
if(req_data['unset']) response['delete_fields'] = req_data['unset'];
|
|
131
134
|
|
|
132
|
-
|
|
135
|
+
self.broadcast('updateDocument', socket, req_data, response, roomInfo)
|
|
133
136
|
}).catch((error) => {
|
|
134
137
|
console.log('error', error)
|
|
135
|
-
|
|
138
|
+
self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
136
139
|
});
|
|
137
140
|
|
|
138
141
|
} catch (error) {
|
|
139
142
|
console.log(error)
|
|
140
|
-
|
|
143
|
+
self.wsManager.send(socket, 'updateDocumentError', error, req_data['organization_id']);
|
|
141
144
|
}
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
/** Delete Document **/
|
|
145
148
|
async deleteDocument(socket, req_data, roomInfo) {
|
|
149
|
+
const self = this;
|
|
150
|
+
|
|
146
151
|
try {
|
|
147
152
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
148
153
|
const collection = db.collection(req_data["collection"]);
|
|
@@ -153,14 +158,14 @@ class CoCreateCrud {
|
|
|
153
158
|
collection.deleteOne(query, function(error, result) {
|
|
154
159
|
if (!error) {
|
|
155
160
|
let response = { ...req_data }
|
|
156
|
-
|
|
161
|
+
self.broadcast('deleteDocument', socket, req_data, response, roomInfo)
|
|
157
162
|
} else {
|
|
158
|
-
|
|
163
|
+
self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
159
164
|
}
|
|
160
165
|
})
|
|
161
166
|
} catch (error) {
|
|
162
167
|
console.log(error);
|
|
163
|
-
|
|
168
|
+
self.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
171
|
|