not-node 6.3.3 → 6.3.4
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
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 };
|
|
@@ -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
|
};
|
|
@@ -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;
|