@cocreate/crud-server 1.5.1 → 1.6.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 +7 -0
- package/package.json +1 -1
- package/src/crud.js +23 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.6.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.5.1...v1.6.0) (2022-05-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* auto detects and updates data type ([ddb1391](https://github.com/CoCreate-app/CoCreate-crud-server/commit/ddb1391928a8a7acccd8d9e4c920adfdeb63f002))
|
|
7
|
+
|
|
1
8
|
## [1.5.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.5.0...v1.5.1) (2022-05-17)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/crud.js
CHANGED
|
@@ -108,11 +108,32 @@ class CoCreateCrud {
|
|
|
108
108
|
console.log(err);
|
|
109
109
|
}
|
|
110
110
|
const query = {"_id": objId };
|
|
111
|
-
const update = {};
|
|
111
|
+
const update = {"$set": {}};
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
if( req_data['set'] )
|
|
115
|
-
|
|
115
|
+
for (const [key, value] of Object.entries(req_data['set'])) {
|
|
116
|
+
let val;
|
|
117
|
+
let valueType = typeof value;
|
|
118
|
+
switch(valueType) {
|
|
119
|
+
case 'string':
|
|
120
|
+
val = value
|
|
121
|
+
break;
|
|
122
|
+
case 'number':
|
|
123
|
+
val = Number(value)
|
|
124
|
+
break;
|
|
125
|
+
case 'object':
|
|
126
|
+
if (Array.isArray(value))
|
|
127
|
+
val = new Array(...value)
|
|
128
|
+
else
|
|
129
|
+
val = new Object(value)
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
val = value
|
|
133
|
+
}
|
|
134
|
+
update.$set[key] = val
|
|
135
|
+
}
|
|
136
|
+
|
|
116
137
|
if( req_data['unset'] )
|
|
117
138
|
update['$unset'] = req_data['unset'].reduce((r, d) => {r[d] = ""; return r}, {});
|
|
118
139
|
update['$set']['organization_id'] = req_data['organization_id'];
|