not-node 5.1.7 → 5.1.10
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/index.js +1 -0
- package/package.json +1 -1
- package/src/exceptions/db.js +2 -2
- package/src/exceptions/http.js +5 -5
- package/src/generic/form.getById.js +30 -0
- package/src/generic/index.js +1 -0
- package/src/generic/logic.js +4 -2
package/index.js
CHANGED
|
@@ -29,6 +29,7 @@ module.exports.Routine = require("./src/model/routine");
|
|
|
29
29
|
module.exports.Common = require("./src/common");
|
|
30
30
|
/** Fields library manager */
|
|
31
31
|
module.exports.Fields = require("./src/fields");
|
|
32
|
+
module.exports.Forms = require("./src/form");
|
|
32
33
|
/** Form validation template **/
|
|
33
34
|
module.exports.Form = require("./src/form").Form;
|
|
34
35
|
/** Form validation template fabric **/
|
package/package.json
CHANGED
package/src/exceptions/db.js
CHANGED
|
@@ -2,7 +2,7 @@ const { notRequestError } = require("not-error");
|
|
|
2
2
|
|
|
3
3
|
//delete wasnt successful, or error, or count of deleted documents dont match requested
|
|
4
4
|
class DBExceptionDeleteWasNotSuccessful extends notRequestError {
|
|
5
|
-
constructor({ params = {}, cause = null }) {
|
|
5
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
6
6
|
super("DB Delete Was Not Successful", { code: 505, ...params }, cause);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
@@ -11,7 +11,7 @@ module.exports.DBExceptionDeleteWasNotSuccessful =
|
|
|
11
11
|
|
|
12
12
|
//delete wasnt successful, bc document is owned by another user
|
|
13
13
|
class DBExceptionDocumentIsNotOwnerByActiveUser extends notRequestError {
|
|
14
|
-
constructor({ params = {}, cause = null }) {
|
|
14
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
15
15
|
super(
|
|
16
16
|
"DB Only Owners Could Delete their documents",
|
|
17
17
|
{ code: 403, ...params },
|
package/src/exceptions/http.js
CHANGED
|
@@ -4,7 +4,7 @@ const { notRequestError } = require("not-error");
|
|
|
4
4
|
|
|
5
5
|
//form of request is not valid
|
|
6
6
|
class HttpExceptionBadRequest extends notRequestError {
|
|
7
|
-
constructor({ params = {}, cause = null }) {
|
|
7
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
8
8
|
super("Bad Request", { code: 400, ...params }, cause);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -12,7 +12,7 @@ module.exports.HttpExceptionBadRequest = HttpExceptionBadRequest;
|
|
|
12
12
|
|
|
13
13
|
//user is not authenticated
|
|
14
14
|
class HttpExceptionUnauthorized extends notRequestError {
|
|
15
|
-
constructor({ params = {}, cause = null }) {
|
|
15
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
16
16
|
super("Unauthorized", { code: 401, ...params }, cause);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -20,7 +20,7 @@ module.exports.HttpExceptionUnauthorized = HttpExceptionUnauthorized;
|
|
|
20
20
|
|
|
21
21
|
//user is too poor to go there
|
|
22
22
|
class HttpExceptionPaymentRequired extends notRequestError {
|
|
23
|
-
constructor({ params = {}, cause = null }) {
|
|
23
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
24
24
|
super("Payment Required", { code: 402, ...params }, cause);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -28,7 +28,7 @@ module.exports.HttpExceptionPaymentRequired = HttpExceptionPaymentRequired;
|
|
|
28
28
|
|
|
29
29
|
//user identity is known, but he has no right to go there
|
|
30
30
|
class HttpExceptionForbidden extends notRequestError {
|
|
31
|
-
constructor({ params = {}, cause = null }) {
|
|
31
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
32
32
|
super("Forbidden", { code: 403, ...params }, cause);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -36,7 +36,7 @@ module.exports.HttpExceptionForbidden = HttpExceptionForbidden;
|
|
|
36
36
|
|
|
37
37
|
//requested address is not exists
|
|
38
38
|
class HttpExceptionNotFound extends notRequestError {
|
|
39
|
-
constructor({ params = {}, cause = null }) {
|
|
39
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
40
40
|
super("Not Found", { code: 404, ...params }, cause);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//DB related validation tools
|
|
2
|
+
const Form = require("../form/form");
|
|
3
|
+
const { firstLetterToUpper } = require("../common");
|
|
4
|
+
//not-node
|
|
5
|
+
const { getIP } = require("../auth");
|
|
6
|
+
//form
|
|
7
|
+
const FIELDS = [
|
|
8
|
+
["targetId", { required: true }, "not-node//objectId"],
|
|
9
|
+
["activeUserId", { required: true }, "not-node//objectId"],
|
|
10
|
+
["activeUser", "not-node//requiredObject"],
|
|
11
|
+
["ip", "not-node//ip"],
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
module.exports = ({ MODULE_NAME, actionName }) => {
|
|
15
|
+
const FORM_NAME = `${MODULE_NAME}:${firstLetterToUpper(actionName)}Form`;
|
|
16
|
+
return class extends Form {
|
|
17
|
+
constructor({ app }) {
|
|
18
|
+
super({ FIELDS, FORM_NAME, app });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
extract(req) {
|
|
22
|
+
return {
|
|
23
|
+
targetId: req.params._id,
|
|
24
|
+
activeUser: req.user,
|
|
25
|
+
activeUserId: req.user._id,
|
|
26
|
+
ip: getIP(req),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
package/src/generic/index.js
CHANGED
package/src/generic/logic.js
CHANGED
|
@@ -7,7 +7,7 @@ const {
|
|
|
7
7
|
} = require("../exceptions/http");
|
|
8
8
|
const isOwnerImported = require("../auth/fields.js").isOwner;
|
|
9
9
|
const { DOCUMENT_OWNER_FIELD_NAME } = require("../auth/const.js");
|
|
10
|
-
const notFilter = require("not-filter")
|
|
10
|
+
const notFilter = require("not-filter");
|
|
11
11
|
|
|
12
12
|
module.exports = ({
|
|
13
13
|
MODEL_NAME,
|
|
@@ -52,6 +52,8 @@ module.exports = ({
|
|
|
52
52
|
static getModelSchema = getModelSchema;
|
|
53
53
|
static getLogic = getLogic;
|
|
54
54
|
static getModelUser = getModelUser;
|
|
55
|
+
static isOwner = isOwner;
|
|
56
|
+
static ownerFieldName = ownerFieldName;
|
|
55
57
|
|
|
56
58
|
static async _create({
|
|
57
59
|
action,
|
|
@@ -547,7 +549,7 @@ module.exports = ({
|
|
|
547
549
|
ip,
|
|
548
550
|
});
|
|
549
551
|
if (shouldOwn) {
|
|
550
|
-
notFilter.
|
|
552
|
+
notFilter.filter.modifyRules(filter, {
|
|
551
553
|
[ownerFieldName]: activeUser._id,
|
|
552
554
|
});
|
|
553
555
|
}
|