@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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "CoCreate-crud-server",
5
5
  "keywords": [
6
6
  "cocreate-crud",
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
- this.broadcast('createDocument', socket, req_data, reponse, roomInfo)
37
+ self.broadcast('createDocument', socket, req_data, reponse, roomInfo)
37
38
  } else {
38
- this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
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
- this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
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
- this.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], roomInfo);
84
+ self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], roomInfo);
83
85
  } else {
84
- this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
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
- this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
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
- this.broadcast('updateDocument', socket, req_data, response, roomInfo)
135
+ self.broadcast('updateDocument', socket, req_data, response, roomInfo)
133
136
  }).catch((error) => {
134
137
  console.log('error', error)
135
- this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
138
+ self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
136
139
  });
137
140
 
138
141
  } catch (error) {
139
142
  console.log(error)
140
- this.wsManager.send(socket, 'updateDocumentError', error, req_data['organization_id']);
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
- this.broadcast('deleteDocument', socket, req_data, response, roomInfo)
161
+ self.broadcast('deleteDocument', socket, req_data, response, roomInfo)
157
162
  } else {
158
- this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
163
+ self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
159
164
  }
160
165
  })
161
166
  } catch (error) {
162
167
  console.log(error);
163
- this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
168
+ self.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
164
169
  }
165
170
  }
166
171