not-node 5.1.26 → 5.1.27

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "5.1.26",
3
+ "version": "5.1.27",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,3 +28,15 @@ class DBExceptionDocumentIsNotFound extends notRequestError {
28
28
  }
29
29
  }
30
30
  module.exports.DBExceptionDocumentIsNotFound = DBExceptionDocumentIsNotFound;
31
+
32
+ class DBExceptionUpdateOneWasNotSuccessful extends notRequestError {
33
+ constructor({ params = {}, cause = null } = {}) {
34
+ super(
35
+ "DB Update One Was Not Successful",
36
+ { code: 505, ...params },
37
+ cause
38
+ );
39
+ }
40
+ }
41
+ module.exports.DBExceptionUpdateOneWasNotSuccessful =
42
+ DBExceptionUpdateOneWasNotSuccessful;
@@ -1,7 +1,8 @@
1
1
  /** @module Model/Routine */
2
2
 
3
3
  const incrementNext = require("./increment");
4
-
4
+ const { DBExceptionUpdateOneWasNotSuccessful } = require("../exceptions/db");
5
+ const { updateResponseSuccess } = require("./utils");
5
6
  class ModelRoutine {
6
7
  static incremental(model) {
7
8
  return model.schema.statics.__incField;
@@ -63,10 +64,14 @@ class ModelRoutine {
63
64
  static async updateWithVersion(model, filter, data) {
64
65
  filter.__latest = true;
65
66
  filter.__closed = false;
66
- const item = await model
67
+ const result = await model
67
68
  .updateOne(filter, data, { returnOriginal: false })
68
69
  .exec();
69
- return model.saveVersion(item._id);
70
+ if (updateResponseSuccess(result, 1)) {
71
+ return model.saveVersion(filter._id);
72
+ } else {
73
+ throw new DBExceptionUpdateOneWasNotSuccessful();
74
+ }
70
75
  }
71
76
 
72
77
  static async updateMany(model, filter, data) {