not-node 6.2.19 → 6.2.21
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 +1 -1
- package/src/form/env_extractors/index.js +2 -2
- package/src/form/extractors/index.js +1 -1
- package/src/manifest/route.js +11 -1
- package/tmpl/files/module.server/layers/forms/_data.ejs +29 -29
- package/tmpl/files/module.server/layers/forms/create.ejs +36 -38
- package/tmpl/files/module.server/layers/forms/listAll.ejs +3 -3
- package/tmpl/files/module.server/layers/forms/listAndCount.ejs +3 -3
- package/tmpl/files/module.server/layers/forms/update.ejs +31 -31
- package/tmpl/files/module.server/layers/forms/validator.ejs +27 -27
package/package.json
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
|
-
_id: require("./_id.js"),
|
|
7
6
|
ID: require("./ID.js"),
|
|
7
|
+
_id: require("./_id.js"),
|
|
8
8
|
activeUser: require("./activeUser.js"),
|
|
9
9
|
ip: require("./ip.js"),
|
|
10
|
-
query: require("./query.js"),
|
|
11
10
|
modelNameID: require("./modelNameID.js"),
|
|
11
|
+
query: require("./query.js"),
|
|
12
12
|
};
|
|
@@ -5,6 +5,6 @@ module.exports = {
|
|
|
5
5
|
activeUserId: require("./activeUserId.js"),
|
|
6
6
|
activeUserModelName: require("./activeUserModelName.js"),
|
|
7
7
|
fromBody: require("./fromBody.js"),
|
|
8
|
-
fromQuery: require("./fromQuery.js"),
|
|
9
8
|
fromParams: require("./fromParams.js"),
|
|
9
|
+
fromQuery: require("./fromQuery.js"),
|
|
10
10
|
};
|
package/src/manifest/route.js
CHANGED
|
@@ -191,7 +191,17 @@ class notRoute {
|
|
|
191
191
|
prepared,
|
|
192
192
|
]);
|
|
193
193
|
//filter result IF actionData.return specified
|
|
194
|
-
|
|
194
|
+
if (typeof result !== "undefined" && result) {
|
|
195
|
+
if (typeof result.toObject === "function") {
|
|
196
|
+
result = result.toObject();
|
|
197
|
+
}
|
|
198
|
+
if (Array.isArray(result)) {
|
|
199
|
+
result = result.map((itm) =>
|
|
200
|
+
itm.toObject ? itm.toObject() : itm
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
notManifestRouteResultFilter.filter(req.notRouteData, result);
|
|
204
|
+
}
|
|
195
205
|
//run after with results, continue without waiting when it finished
|
|
196
206
|
return this.executeFunction(modRoute, CONST_AFTER_ACTION, [
|
|
197
207
|
req,
|
|
@@ -3,33 +3,33 @@ const { MODULE_NAME } = require("../const");
|
|
|
3
3
|
const Form = require("not-node").Form;
|
|
4
4
|
|
|
5
5
|
const FIELDS = [
|
|
6
|
-
|
|
6
|
+
<% if (fields && Array.isArray(fields)) { %>
|
|
7
7
|
<% for(let field of fields){ %>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
const FORM_NAME = `${MODULE_NAME}:_<%- ModelName %>DataForm`;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//const validateTitle = require("./validators/title.js");
|
|
19
|
-
|
|
20
|
-
module.exports = class _DataForm extends Form {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
8
|
+
<%- `"${field}",` -%>
|
|
9
|
+
<% } %>
|
|
10
|
+
<% } %>
|
|
11
|
+
["owner", "not-node//owner"],
|
|
12
|
+
["ownerModel", "not-node//ownerModel"],
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const FORM_NAME = `${MODULE_NAME}:_<%- ModelName %>DataForm`;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
//const validateTitle = require("./validators/title.js");
|
|
19
|
+
|
|
20
|
+
module.exports = class _DataForm extends Form {
|
|
21
|
+
constructor({ app }) {
|
|
22
|
+
super({ FIELDS, FORM_NAME, app });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
extract(data) {
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getFormValidationRules() {
|
|
30
|
+
return [
|
|
31
|
+
//add validators here
|
|
32
|
+
//validateTitle,
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -3,45 +3,43 @@ const { MODULE_NAME } = require("../const");
|
|
|
3
3
|
//DB related validation tools
|
|
4
4
|
const Form = require("not-node").Form;
|
|
5
5
|
//form
|
|
6
|
-
const FIELDS = [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
<% } %>
|
|
12
|
-
];
|
|
6
|
+
const FIELDS = [
|
|
7
|
+
["activeUser", "not-node//requiredObject"],
|
|
8
|
+
["data", `${MODULE_NAME}//_<%- ModelName %>_data`],
|
|
9
|
+
["ip", "not-node//ip"],
|
|
10
|
+
];
|
|
13
11
|
|
|
14
|
-
const FORM_NAME = `${MODULE_NAME}:<%- ModelName %>CreateForm`;
|
|
12
|
+
const FORM_NAME = `${MODULE_NAME}:<%- ModelName %>CreateForm`;
|
|
15
13
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
module.exports = class <%- ModelName %>CreateForm extends Form {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
**/
|
|
17
|
+
module.exports = class <%- ModelName %>CreateForm extends Form {
|
|
18
|
+
constructor({ app }) {
|
|
19
|
+
super({ FIELDS, FORM_NAME, app });
|
|
20
|
+
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Extracts data
|
|
24
|
+
* @param {ExpressRequest} req expressjs request object
|
|
25
|
+
* @return {Object} forma data
|
|
26
|
+
**/
|
|
27
|
+
extract(req) {
|
|
28
|
+
const ip = getIP(req);
|
|
29
|
+
const instructions = {
|
|
32
30
|
<% if (fields && Array.isArray(fields)) { %>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
31
|
+
<% for(let field of fields){ %>
|
|
32
|
+
<%- field+': fromBody" ,' -%>
|
|
33
|
+
<% } %>
|
|
34
|
+
<% } %>
|
|
35
|
+
owner: "activeUserId",
|
|
36
|
+
ownerModel: "activeUserModelName",
|
|
37
|
+
};
|
|
38
|
+
const data = this.extractByInstructions(req, instructions);
|
|
39
|
+
return {
|
|
40
|
+
activeUser: req.user,
|
|
41
|
+
ip,
|
|
42
|
+
data,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
@@ -2,7 +2,7 @@ const notNode = require("not-node");
|
|
|
2
2
|
const { MODULE_NAME } = require("../const");
|
|
3
3
|
|
|
4
4
|
module.exports = notNode.Generic.GenericListAndCountForm({
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
MODULE_NAME,
|
|
6
|
+
MODEL_NAME: "<%- ModelName %>",
|
|
7
7
|
actionName: "listAll",
|
|
8
|
-
});
|
|
8
|
+
});
|
|
@@ -2,7 +2,7 @@ const notNode = require("not-node");
|
|
|
2
2
|
const { MODULE_NAME } = require("../const");
|
|
3
3
|
|
|
4
4
|
module.exports = notNode.Generic.GenericListAndCountForm({
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
MODULE_NAME,
|
|
6
|
+
MODEL_NAME: "<%- ModelName %>",
|
|
7
7
|
actionName: "listAndCount",
|
|
8
|
-
});
|
|
8
|
+
});
|
|
@@ -3,38 +3,38 @@ const Form = require("not-node").Form;
|
|
|
3
3
|
const getIP = require("not-node").Auth.getIP;
|
|
4
4
|
|
|
5
5
|
const FIELDS = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
["targetId", { required: true }, "not-node//objectId"],
|
|
7
|
+
["activeUser", "not-node//requiredObject"],
|
|
8
|
+
["data", `${MODULE_NAME}//_<%- ModelName %>_data`], //sub forms validators should start with underscore
|
|
9
9
|
["ip", "not-node//ip"],
|
|
10
|
-
];
|
|
11
|
-
const FORM_NAME = `${
|
|
10
|
+
];
|
|
11
|
+
const FORM_NAME = `${MODULE_NAME}:<%- ModelName %>UpdateForm`;
|
|
12
12
|
|
|
13
|
-
module.exports = class <%- ModelName %>UpdateForm extends Form {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
module.exports = class <%- ModelName %>UpdateForm extends Form {
|
|
14
|
+
constructor({ app }) {
|
|
15
|
+
super({ FIELDS, FORM_NAME, app });
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
extract(req) {
|
|
19
|
+
const instructions = {
|
|
20
20
|
<% if (fields && Array.isArray(fields)) { %>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
21
|
+
<% for(let field of fields){ %>
|
|
22
|
+
<%- field+': "fromBody" ,' -%>
|
|
23
|
+
<% } %>
|
|
24
|
+
<% } %>
|
|
25
|
+
owner: "fromBody",
|
|
26
|
+
ownerModel: "fromBody",
|
|
27
|
+
};
|
|
28
|
+
const data = this.extractByInstructions(req, instructions);
|
|
29
|
+
if (!req.user.isRoot() && !req.user.isAdmin()) {
|
|
30
|
+
data.owner = req.user._id;
|
|
31
|
+
data.ownerModel = "User";
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
targetId: req.params._id.toString(),
|
|
35
|
+
activeUser: req.user,
|
|
36
|
+
data,
|
|
37
|
+
ip: getIP(req),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -2,31 +2,31 @@ const notNode = require("not-node");
|
|
|
2
2
|
const { notValidationError } = require("not-error");
|
|
3
3
|
|
|
4
4
|
module.exports = async (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
);
|
|
5
|
+
/**
|
|
6
|
+
* Values to validate in form
|
|
7
|
+
*/
|
|
8
|
+
{owner, ownerModel, vals, to , validate },
|
|
9
|
+
/**
|
|
10
|
+
* special container to pass around global validation libs, CONSTs and inject other entities
|
|
11
|
+
*/
|
|
12
|
+
validationEnvs
|
|
13
|
+
) => {
|
|
14
|
+
//some preparations
|
|
15
|
+
if (
|
|
16
|
+
//vals checks
|
|
17
|
+
) {
|
|
18
|
+
throw new notValidationError(
|
|
19
|
+
"<%- ModuleName %>:validation_error",
|
|
20
|
+
{
|
|
21
|
+
//vals: ["%- ModuleName %>:vals_should_be_valid"],
|
|
22
|
+
},
|
|
23
|
+
undefined, //no source error, its custom exception
|
|
24
|
+
{
|
|
25
|
+
//information
|
|
26
|
+
//vals,
|
|
27
|
+
//owner,
|
|
28
|
+
//ownerModel
|
|
31
29
|
}
|
|
32
|
-
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
};
|