@domain.js/main 0.1.10 → 0.1.11

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.
@@ -24,14 +24,23 @@ function Main(cnf, deps, utils) {
24
24
  * @param _cols Allow columns to be updated
25
25
  * @returns The resource that has been updated
26
26
  */
27
- const modify = (Model, model, params, isAdmin = false, _cols) => {
27
+ const modify = async (Model, model, params, isAdmin = false, _cols) => {
28
28
  const cols = _cols || Model.editableCols || Model.writableCols || [];
29
29
  const attr = pickParams(params, cols, Model, isAdmin);
30
30
  // 避免id 被篡改,强制删除id属性
31
31
  if (attr.id)
32
32
  delete attr.id;
33
33
  Object.assign(model, attr);
34
- return model.save();
34
+ const fields = model.changed();
35
+ if (!Array.isArray(fields) || !fields.length)
36
+ return model;
37
+ try {
38
+ return await model.save();
39
+ }
40
+ catch (e) {
41
+ Object.assign(model, model.previous());
42
+ throw e;
43
+ }
35
44
  };
36
45
  /**
37
46
  * Restful add(C of CRUD) for create a resource
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {