@cocreate/crud-server 1.3.0 → 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 +7 -0
- package/package.json +1 -1
- package/src/crud.js +13 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
# [1.3.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.2.10...v1.3.0) (2022-03-03)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/crud.js
CHANGED
|
@@ -20,7 +20,6 @@ class CoCreateCrud {
|
|
|
20
20
|
|
|
21
21
|
/** Create Document **/
|
|
22
22
|
async createDocument(socket, req_data, roomInfo){
|
|
23
|
-
const self = this;
|
|
24
23
|
if(!req_data.data) return;
|
|
25
24
|
|
|
26
25
|
try{
|
|
@@ -34,9 +33,9 @@ class CoCreateCrud {
|
|
|
34
33
|
// let isFlat = req_data.isFlat == false ? false : true;
|
|
35
34
|
// const response_data = isFlat ? encodeObject(response) : response;
|
|
36
35
|
const response_data = response;
|
|
37
|
-
|
|
36
|
+
this.broadcast('createDocument', socket, req_data, reponse, roomInfo)
|
|
38
37
|
} else {
|
|
39
|
-
|
|
38
|
+
this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
40
39
|
}
|
|
41
40
|
});
|
|
42
41
|
}catch(error){
|
|
@@ -51,7 +50,6 @@ class CoCreateCrud {
|
|
|
51
50
|
this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
|
|
52
51
|
return;
|
|
53
52
|
}
|
|
54
|
-
const self = this;
|
|
55
53
|
|
|
56
54
|
try {
|
|
57
55
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
@@ -81,9 +79,9 @@ class CoCreateCrud {
|
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
let isFlat = req_data.isFlat == true ? true : false;
|
|
84
|
-
|
|
82
|
+
this.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], roomInfo);
|
|
85
83
|
} else {
|
|
86
|
-
|
|
84
|
+
this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
87
85
|
}
|
|
88
86
|
});
|
|
89
87
|
} catch (error) {
|
|
@@ -94,8 +92,6 @@ class CoCreateCrud {
|
|
|
94
92
|
|
|
95
93
|
/** Update Document **/
|
|
96
94
|
async updateDocument(socket, req_data, roomInfo) {
|
|
97
|
-
const self = this;
|
|
98
|
-
|
|
99
95
|
try {
|
|
100
96
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
101
97
|
const collection = db.collection(req_data["collection"]);
|
|
@@ -108,7 +104,6 @@ class CoCreateCrud {
|
|
|
108
104
|
console.log(err);
|
|
109
105
|
}
|
|
110
106
|
const query = {"_id": objId };
|
|
111
|
-
|
|
112
107
|
const update = {};
|
|
113
108
|
|
|
114
109
|
|
|
@@ -127,7 +122,6 @@ class CoCreateCrud {
|
|
|
127
122
|
projection: projection,
|
|
128
123
|
}
|
|
129
124
|
).then((result) => {
|
|
130
|
-
|
|
131
125
|
let isFlat = req_data.isFlat == true ? true : false;
|
|
132
126
|
let response_data = result.value || {};
|
|
133
127
|
|
|
@@ -135,21 +129,20 @@ class CoCreateCrud {
|
|
|
135
129
|
|
|
136
130
|
if(req_data['unset']) response['delete_fields'] = req_data['unset'];
|
|
137
131
|
|
|
138
|
-
|
|
132
|
+
this.broadcast('updateDocument', socket, req_data, response, roomInfo)
|
|
139
133
|
}).catch((error) => {
|
|
140
|
-
|
|
134
|
+
console.log('error', error)
|
|
135
|
+
this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
141
136
|
});
|
|
142
137
|
|
|
143
138
|
} catch (error) {
|
|
144
139
|
console.log(error)
|
|
145
|
-
|
|
140
|
+
this.wsManager.send(socket, 'updateDocumentError', error, req_data['organization_id']);
|
|
146
141
|
}
|
|
147
142
|
}
|
|
148
143
|
|
|
149
144
|
/** Delete Document **/
|
|
150
145
|
async deleteDocument(socket, req_data, roomInfo) {
|
|
151
|
-
const self = this;
|
|
152
|
-
|
|
153
146
|
try {
|
|
154
147
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
155
148
|
const collection = db.collection(req_data["collection"]);
|
|
@@ -160,9 +153,9 @@ class CoCreateCrud {
|
|
|
160
153
|
collection.deleteOne(query, function(error, result) {
|
|
161
154
|
if (!error) {
|
|
162
155
|
let response = { ...req_data }
|
|
163
|
-
|
|
156
|
+
this.broadcast('deleteDocument', socket, req_data, response, roomInfo)
|
|
164
157
|
} else {
|
|
165
|
-
|
|
158
|
+
this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
|
|
166
159
|
}
|
|
167
160
|
})
|
|
168
161
|
} catch (error) {
|
|
@@ -173,14 +166,14 @@ class CoCreateCrud {
|
|
|
173
166
|
|
|
174
167
|
broadcast(component, socket, req_data, response, roomInfo) {
|
|
175
168
|
if (req_data.broadcast_sender != false) {
|
|
176
|
-
|
|
169
|
+
this.wsManager.send(socket, component, { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo);
|
|
177
170
|
}
|
|
178
171
|
|
|
179
172
|
if (req_data.broadcast !== false) {
|
|
180
173
|
if (req_data.room) {
|
|
181
|
-
|
|
174
|
+
this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, component, response, true, roomInfo);
|
|
182
175
|
} else {
|
|
183
|
-
|
|
176
|
+
this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, component, response, true, roomInfo)
|
|
184
177
|
}
|
|
185
178
|
}
|
|
186
179
|
process.emit('changed-document', response)
|