@cocreate/crud-server 1.4.0 → 1.4.3

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,25 @@
1
+ ## [1.4.3](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.4.2...v1.4.3) (2022-05-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * updateDocument now sends updated data ([f18d5e7](https://github.com/CoCreate-app/CoCreate-crud-server/commit/f18d5e7705658463326b276771825393603279e0))
7
+
8
+ ## [1.4.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.4.1...v1.4.2) (2022-05-12)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * createDocument requires organization_id to be stored ([259f56d](https://github.com/CoCreate-app/CoCreate-crud-server/commit/259f56daadc6b9e148f054c0ba2cf04443122a6a))
14
+
15
+ ## [1.4.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.4.0...v1.4.1) (2022-05-06)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * replace ObjectID with ObjectId due to mongodb depreciation ([93e4294](https://github.com/CoCreate-app/CoCreate-crud-server/commit/93e42944447357ec6a244b72ce968bbd8ff5c93d))
21
+ * update config organization_Id to organization_id ([996611b](https://github.com/CoCreate-app/CoCreate-crud-server/commit/996611baf2b2d3afbf895ef193ae15ba7226e77a))
22
+
1
23
  # [1.4.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.4...v1.4.0) (2022-04-01)
2
24
 
3
25
 
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
2
  config: {
3
3
  "apiKey": "2061acef-0451-4545-f754-60cf8160",
4
- "organization_Id": "5ff747727005da1c272740ab",
4
+ "organization_id": "5ff747727005da1c272740ab",
5
5
  "host": "general.cocreate.app"
6
6
  },
7
7
  "sources": [
package/docs/index.html CHANGED
@@ -124,7 +124,7 @@
124
124
  var config = {
125
125
  apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
126
126
  securityKey: 'f26baf68-e3a9-45fc-effe-502e47116265',
127
- organization_Id: '5de0387b12e200ea63204d6c'
127
+ organization_id: '5de0387b12e200ea63204d6c'
128
128
  }
129
129
  </script>
130
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.4.0",
3
+ "version": "1.4.3",
4
4
  "description": "CoCreate-crud-server",
5
5
  "keywords": [
6
6
  "cocreate-crud",
package/src/crud.js CHANGED
@@ -1,4 +1,4 @@
1
- const {ObjectID} = require("mongodb");
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.ops[0]._id, data:result.ops[0] }
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,7 +59,7 @@ class CoCreateCrud {
58
59
  const collection = db.collection(req_data["collection"]);
59
60
 
60
61
  const query = {
61
- "_id": new ObjectID(req_data["document_id"])
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'];
@@ -83,6 +84,7 @@ class CoCreateCrud {
83
84
  let isFlat = req_data.isFlat == true ? true : false;
84
85
  self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], socketInfo);
85
86
  } else {
87
+ console.log('readDocument error', error)
86
88
  self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
87
89
  }
88
90
  });
@@ -98,10 +100,10 @@ class CoCreateCrud {
98
100
  try {
99
101
  const db = this.dbClient.db(req_data['organization_id']);
100
102
  const collection = db.collection(req_data["collection"]);
101
- let objId = new ObjectID();
103
+ let objId = new ObjectId();
102
104
  try {
103
105
  if (req_data["document_id"]) {
104
- objId = new ObjectID(req_data["document_id"]);
106
+ objId = new ObjectId(req_data["document_id"]);
105
107
  }
106
108
  } catch (err) {
107
109
  console.log(err);
@@ -110,8 +112,10 @@ class CoCreateCrud {
110
112
  const update = {};
111
113
 
112
114
 
113
- if( req_data['set'] ) update['$set'] = replaceArray(req_data['set']);
114
- if( req_data['unset'] ) update['$unset'] = req_data['unset'].reduce((r, d) => {r[d] = ""; return r}, {});
115
+ if( req_data['set'] )
116
+ update['$set'] = replaceArray(req_data['set']);
117
+ if( req_data['unset'] )
118
+ update['$unset'] = req_data['unset'].reduce((r, d) => {r[d] = ""; return r}, {});
115
119
  update['$set']['organization_id'] = req_data['organization_id'];
116
120
 
117
121
  let projection = {}
@@ -128,7 +132,7 @@ class CoCreateCrud {
128
132
  let isFlat = req_data.isFlat == true ? true : false;
129
133
  let response_data = result.value || {};
130
134
 
131
- let response = { ...req_data, document_id: response_data._id, data: isFlat ? encodeObject(response_data) : response_data };
135
+ let response = { ...req_data, document_id: response_data._id, data: isFlat ? encodeObject(req_data['set']) : req_data['set'] };
132
136
 
133
137
  if(req_data['unset']) response['delete_fields'] = req_data['unset'];
134
138
 
@@ -152,7 +156,7 @@ class CoCreateCrud {
152
156
  const db = this.dbClient.db(req_data['organization_id']);
153
157
  const collection = db.collection(req_data["collection"]);
154
158
  const query = {
155
- "_id": new ObjectID(req_data["document_id"])
159
+ "_id": new ObjectId(req_data["document_id"])
156
160
  };
157
161
 
158
162
  collection.deleteOne(query, function(error, result) {
package/src/list.js CHANGED
@@ -1,4 +1,4 @@
1
- const {ObjectID} = require("mongodb");
1
+ const {ObjectId} = require("mongodb");
2
2
 
3
3
  class CoCreateList {
4
4
  constructor(wsManager, dbClient) {
@@ -158,7 +158,7 @@ class CoCreateList {
158
158
  query[key] = {};
159
159
  }
160
160
 
161
- if (item.name == "_id") item.value = item.value.map(v => new ObjectID(v))
161
+ if (item.name == "_id") item.value = item.value.map(v => new ObjectId(v))
162
162
 
163
163
  switch (item.operator) {
164
164
  case '$contain':