not-node 5.1.35 → 5.1.38

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.35",
3
+ "version": "5.1.38",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,8 +1,14 @@
1
1
  const getApp = require("../getApp.js"),
2
+ Form = require("../form").Form,
2
3
  HttpExceptions = require("../exceptions/http"),
3
4
  configInit = require("not-config"),
4
5
  { sayForModule } = require("not-locale"),
5
- { objHas, isFunc, executeFunctionAsAsync } = require("../common"),
6
+ {
7
+ objHas,
8
+ isFunc,
9
+ executeFunctionAsAsync,
10
+ firstLetterToUpper,
11
+ } = require("../common"),
6
12
  LogInit = require("not-log");
7
13
 
8
14
  module.exports = ({
@@ -79,6 +85,23 @@ module.exports = ({
79
85
  }
80
86
  };
81
87
 
88
+ const createDefaultForm = function ({ actionName }) {
89
+ const FIELDS = [
90
+ ["activeUser", "not-node//requiredObject"],
91
+ ["data", `${MODULE_NAME}//_data`],
92
+ ["ip", "not-node//ip"],
93
+ ];
94
+ const FORM_NAME = `${MODULE_NAME}:${firstLetterToUpper(
95
+ actionName
96
+ )}Form`;
97
+ const cls = class extends Form {
98
+ constructor({ app }) {
99
+ super({ FIELDS, FORM_NAME, app, MODULE_NAME });
100
+ }
101
+ };
102
+ return new cls({ app: getApp() });
103
+ };
104
+
82
105
  const getForm = (actionName) => {
83
106
  const form = getApp().getForm(
84
107
  [MODULE_NAME, `${MODEL_NAME}.${actionName}`].join("//")
@@ -86,7 +109,11 @@ module.exports = ({
86
109
  if (form) {
87
110
  return form;
88
111
  }
89
- return getApp().getForm([MODULE_NAME, actionName].join("//"));
112
+ const form2 = getApp().getForm([MODULE_NAME, actionName].join("//"));
113
+ if (form2) {
114
+ return form2;
115
+ }
116
+ return createDefaultForm({ actionName, MODULE_NAME });
90
117
  };
91
118
 
92
119
  const beforeDecorator = async (req, res, next) => {
package/src/form/form.js CHANGED
@@ -32,6 +32,7 @@ class Form {
32
32
  **/
33
33
  #FORM_NAME;
34
34
  #MODEL_NAME;
35
+ #MODULE_NAME;
35
36
  #PROTO_FIELDS;
36
37
  #VALIDATOR;
37
38
  #EXTRACTORS = {
@@ -46,12 +47,14 @@ class Form {
46
47
  FIELDS,
47
48
  FORM_NAME,
48
49
  MODEL_NAME,
50
+ MODULE_NAME,
49
51
  app,
50
52
  EXTRACTORS = {},
51
53
  ENV_EXTRACTORS = {},
52
54
  }) {
53
55
  this.#FORM_NAME = FORM_NAME;
54
56
  this.#MODEL_NAME = MODEL_NAME;
57
+ this.#MODULE_NAME = MODULE_NAME;
55
58
  this.#PROTO_FIELDS = FIELDS;
56
59
  this.#createValidationSchema(app);
57
60
  this.#augmentValidationSchema();
@@ -68,6 +71,10 @@ class Form {
68
71
  return undefined;
69
72
  }
70
73
 
74
+ getModuleName() {
75
+ return this.#MODULE_NAME;
76
+ }
77
+
71
78
  /**
72
79
  * Extract data from ExpressRequest object and validates it
73
80
  * returns it or throws
@@ -7,13 +7,13 @@ class VersioningExceptionSameOldData extends notError {
7
7
  }
8
8
  module.exports.VersioningExceptionSameOldData = VersioningExceptionSameOldData;
9
9
 
10
- class VersioningExceptionNoPpreviousVersions extends notError {
10
+ class VersioningExceptioNoPreviousVersions extends notError {
11
11
  constructor() {
12
12
  super("not-node:versioning_error_no_previous_versions");
13
13
  }
14
14
  }
15
- module.exports.VersioningExceptionNoPpreviousVersions =
16
- VersioningExceptionNoPpreviousVersions;
15
+ module.exports.VersioningExceptioNoPreviousVersions =
16
+ VersioningExceptioNoPreviousVersions;
17
17
 
18
18
  class IncrementExceptionIDGeneratorRebaseFailed extends notError {
19
19
  constructor() {
@@ -2,7 +2,7 @@
2
2
 
3
3
  const incrementNext = require("./increment");
4
4
  const { DBExceptionUpdateOneWasNotSuccessful } = require("../exceptions/db");
5
- const { updateResponseSuccess } = require("./utils");
5
+ //const { updateResponseSuccess } = require("./utils");
6
6
  class ModelRoutine {
7
7
  static incremental(model) {
8
8
  return model.schema.statics.__incField;
@@ -57,6 +57,7 @@ class ModelRoutine {
57
57
  return model
58
58
  .findOneAndUpdate(filter, data, {
59
59
  returnOriginal: false,
60
+ returnDocument: "fater",
60
61
  new: true,
61
62
  })
62
63
  .exec();
@@ -65,11 +66,15 @@ class ModelRoutine {
65
66
  static async updateWithVersion(model, filter, data) {
66
67
  filter.__latest = true;
67
68
  filter.__closed = false;
68
- const result = await model.updateOne(filter, data, {
69
- returnOriginal: false,
70
- });
71
- if (updateResponseSuccess(result, 1)) {
72
- return model.saveVersion(filter._id);
69
+ const result = await model
70
+ .findOneAndUpdate(filter, data, {
71
+ returnOriginal: false,
72
+ returnDocument: "fater",
73
+ new: true,
74
+ })
75
+ .exec();
76
+ if (result) {
77
+ return model.saveVersion(result._id);
73
78
  } else {
74
79
  throw new DBExceptionUpdateOneWasNotSuccessful();
75
80
  }
@@ -12,7 +12,7 @@ const TECH_FIELDS = [
12
12
  ];
13
13
 
14
14
  const {
15
- VersioningExceptioNoPpreviousVersions,
15
+ VersioningExceptioNoPreviousVersions,
16
16
  VersioningExceptionSameOldData,
17
17
  } = require("./exceptions.js");
18
18
 
@@ -74,7 +74,7 @@ class ModelVersioning {
74
74
  previous.toObject()
75
75
  );
76
76
  } else {
77
- throw new VersioningExceptioNoPpreviousVersions();
77
+ throw new VersioningExceptioNoPreviousVersions();
78
78
  }
79
79
  }
80
80