@cocreate/crud-server 1.3.4 → 1.4.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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.4.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.4...v1.4.0) (2022-04-01)
2
+
3
+
4
+ ### Features
5
+
6
+ * readCollections to return a list of collections ([2ad15d4](https://github.com/CoCreate-app/CoCreate-crud-server/commit/2ad15d43baf22c6dabbf56582cac182dec8876ad))
7
+
1
8
  ## [1.3.4](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.3...v1.3.4) (2022-03-06)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
4
4
  "description": "CoCreate-crud-server",
5
5
  "keywords": [
6
6
  "cocreate-crud",
package/src/list.js CHANGED
@@ -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('readCollectionList', (socket, data, socketInfo) => this.readCollectionList(socket, data, socketInfo));
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.readCollectionList(socket, req_data, socketInfo);
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 readCollectionList(socket, data, socketInfo) {
128
+ async readCollections(socket, data, socketInfo) {
132
129
  try {
133
- var collections = [];
134
- const db = this.dbClient.db(req_data['organization_id']);
135
- collections = await db.listCollections().toArray().then(infos => {
136
- var result = [];
137
- infos.forEach(function(item) {
138
- let __uuid = item.info.uuid.toString('hex')
139
- result.push({
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
  *