not-node 6.3.3 → 6.3.5

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": "6.3.3",
3
+ "version": "6.3.5",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/form/form.js CHANGED
@@ -124,6 +124,16 @@ class Form {
124
124
  };
125
125
  }
126
126
 
127
+ /**
128
+ * Chance to edit prepared data
129
+ *
130
+ * @param {import('../types').PreparedData} value
131
+ * @return {Promise<import('../types').PreparedData>}
132
+ */
133
+ async afterExtract(value) {
134
+ return value;
135
+ }
136
+
127
137
  #addEnvExtractors(extractors = {}) {
128
138
  if (extractors) {
129
139
  this.#ENV_EXTRACTORS = { ...this.#ENV_EXTRACTORS, ...extractors };
@@ -18,9 +18,9 @@ module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
18
18
  }
19
19
 
20
20
  async extract(req) {
21
- return {
21
+ return this.afterExtract({
22
22
  ...this.extractRequestEnvs(req),
23
- };
23
+ });
24
24
  }
25
25
  };
26
26
  };
@@ -20,10 +20,10 @@ module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
20
20
 
21
21
  async extract(req) {
22
22
  const envs = this.extractRequestEnvs(req);
23
- return {
23
+ return this.afterExtract({
24
24
  ...envs,
25
25
  targetId: envs.modelNameID,
26
- };
26
+ });
27
27
  }
28
28
  };
29
29
  };
@@ -21,9 +21,9 @@ module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
21
21
 
22
22
  async extract(req) {
23
23
  const envs = this.extractRequestEnvs(req);
24
- return {
24
+ return this.afterExtract({
25
25
  ...envs,
26
- };
26
+ });
27
27
  }
28
28
  };
29
29
  };
@@ -0,0 +1,55 @@
1
+ const Form = require("../form/form");
2
+ const { firstLetterToUpper } = require("../common");
3
+ const notFilter = require("not-filter");
4
+
5
+ const FIELDS = [
6
+ ["query", `not-filter//_filterQuery`],
7
+ ["activeUserId", { required: true }, "not-node//objectId"],
8
+ ["activeUser", "not-node//requiredObject"],
9
+ ["ip", "not-node//ip"],
10
+ ];
11
+
12
+ /**
13
+ * Generates generic form to get perform list action
14
+ *
15
+ * @param {object} params
16
+ * @param {string} params.MODULE_NAME //module name
17
+ * @param {string} params.MODEL_NAME //model name
18
+ * @param {string} params.actionName //action name
19
+ * @return {Form} form class definition
20
+ */
21
+ const FactoryFormList = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
22
+ const FORM_NAME = `${MODULE_NAME}:${MODEL_NAME}:${firstLetterToUpper(
23
+ actionName
24
+ )}Form`;
25
+
26
+ return class extends Form {
27
+ constructor({ app }) {
28
+ super({ FIELDS, FORM_NAME, app });
29
+ }
30
+
31
+ /**
32
+ *
33
+ *
34
+ * @param {import('../types').notNodeExpressRequest} req
35
+ * @return {Promise<import('../types').PreparedData>}
36
+ */
37
+ async extract(req) {
38
+ const envs = this.extractRequestEnvs(req);
39
+ if (!req.user.isRoot() && !req.user.isAdmin()) {
40
+ envs.query.filter = notFilter.filter.modifyRules(
41
+ envs.query.filter,
42
+ {
43
+ owner: req.user._id,
44
+ }
45
+ );
46
+ }
47
+
48
+ return this.afterExtract({
49
+ ...envs,
50
+ });
51
+ }
52
+ };
53
+ };
54
+
55
+ module.exports = FactoryFormList;
@@ -44,9 +44,9 @@ const FactoryFormListAndCount = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
44
44
  }
45
45
  );
46
46
  }
47
- return {
47
+ return this.afterExtract({
48
48
  ...envs,
49
- };
49
+ });
50
50
  }
51
51
  };
52
52
  };
@@ -4,8 +4,10 @@ module.exports.GenericGetByIdForm = require("./form.getById.js");
4
4
  module.exports.GenericGetByIDForm = require("./form.getByID.js");
5
5
  module.exports.GenericAuthorizedActionForm = require("./form.authorizedAction.js");
6
6
  module.exports.GenericListAndCountForm = require("./form.listAndCount.js");
7
+ module.exports.GenericListForm = require("./form.list.js");
7
8
 
8
9
  const FORMS = {};
10
+
9
11
  module.exports.setCustomGenericForm = (name, factory) => {
10
12
  FORMS[name] = factory;
11
13
  };