not-node 6.3.50 → 6.3.52
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 +4 -4
- package/src/common.js +8 -5
- package/src/core/fields/createdAt.js +1 -1
- package/src/exceptions/action.js +100 -0
- package/src/exceptions/db.js +5 -4
- package/src/exceptions/logic.js +14 -0
- package/src/generic/logic.js +2 -2
- package/src/logic/action.runner.js +15 -0
- package/src/logic/actions/increment/getByID.js +23 -0
- package/src/logic/actions/increment/index.js +1 -0
- package/src/logic/actions/index.js +8 -0
- package/src/logic/actions/standart/count.js +24 -0
- package/src/logic/actions/standart/create.js +21 -0
- package/src/logic/actions/standart/delete.js +28 -0
- package/src/logic/actions/standart/get.js +38 -0
- package/src/logic/actions/standart/getRaw.js +31 -0
- package/src/logic/actions/standart/index.js +11 -0
- package/src/logic/actions/standart/list.js +27 -0
- package/src/logic/actions/standart/listAll.js +21 -0
- package/src/logic/actions/standart/listAndCount.js +29 -0
- package/src/logic/actions/standart/update.js +30 -0
- package/src/logic/actions.before/index.js +7 -0
- package/src/logic/actions.before/ownage/index.js +3 -0
- package/src/logic/actions.before/ownage/ownage.js +57 -0
- package/src/logic/actions.before/populate/index.js +3 -0
- package/src/logic/actions.before/populate/populate.js +3 -0
- package/src/logic/actions.lib.js +18 -0
- package/src/logic/generic.action.after.js +6 -0
- package/src/logic/generic.action.before.js +6 -0
- package/src/logic/generic.js +51 -0
- package/src/logic/logic.js +224 -0
- package/src/logic/named.actions.pipes.js +102 -0
- package/src/model/default.js +44 -8
- package/src/model/increment.js +3 -2
- package/src/model/utils.js +64 -37
- package/src/types.js +48 -0
- package/test/auth/fields.js +6 -6
- package/test/common.js +2 -2
- package/test/identity/providers/session.js +14 -14
- package/test/model/default.js +9 -4
- package/test/model/proto.js +2 -0
- package/test/model/utils.js +50 -0
- package/test/model/versioning.js +1 -1
- package/test/notModel.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "not-node",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.52",
|
|
4
4
|
"description": "node complimentary part for client side notFramework.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -56,8 +56,6 @@
|
|
|
56
56
|
"jsonwebtoken": "^9.0.0",
|
|
57
57
|
"lower-case": "*",
|
|
58
58
|
"method-override": "^3.0.0",
|
|
59
|
-
"mock-require": "^3.0.3",
|
|
60
|
-
"mongoose": "*",
|
|
61
59
|
"mongoose-validator": "*",
|
|
62
60
|
"nconf": "*",
|
|
63
61
|
"not-config": "*",
|
|
@@ -91,7 +89,9 @@
|
|
|
91
89
|
"jsdoc": "^4.0.0",
|
|
92
90
|
"mocha": "*",
|
|
93
91
|
"mocha-suppress-logs": "^0.3.1",
|
|
94
|
-
"
|
|
92
|
+
"mock-require": "^3.0.3",
|
|
93
|
+
"mongodb-memory-server": "^9.1.6",
|
|
94
|
+
"mongoose": "^8.1.1",
|
|
95
95
|
"not-error": "^0.2.9",
|
|
96
96
|
"not-validation": "^0.0.9",
|
|
97
97
|
"npm-run-all": "^4.1.5",
|
package/src/common.js
CHANGED
|
@@ -381,23 +381,26 @@ module.exports.getValueFromEnv = getValueFromEnv;
|
|
|
381
381
|
* @param {object} sign signature object {fieldName: someValueOfTargetType}
|
|
382
382
|
* @param {boolean} [strict=true] if you need exact properties as in signature, when false - properties not described in signature are ok
|
|
383
383
|
* @param {boolean} [typeStrict=true] compares types of properties in obj and signature
|
|
384
|
+
* @param {boolean} [valueStrict=false] compares values of properties in obj and signature
|
|
384
385
|
* @return {boolean} true if object structured as signature
|
|
385
386
|
*/
|
|
386
387
|
const compareObjectSignatures = (
|
|
387
388
|
obj,
|
|
388
389
|
sign,
|
|
389
390
|
strict = true,
|
|
390
|
-
typeStrict = true
|
|
391
|
+
typeStrict = true,
|
|
392
|
+
valueStrict = false
|
|
391
393
|
) => {
|
|
392
394
|
const objKeys = Object.keys(obj);
|
|
393
395
|
const signKeys = Object.keys(sign);
|
|
394
396
|
const checkKey = (key) => {
|
|
395
397
|
if (objKeys.includes(key)) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
return
|
|
398
|
+
const isTypeStrict = typeof obj[key] === typeof sign[key];
|
|
399
|
+
const isValueStrict = obj[key] === sign[key];
|
|
400
|
+
if (typeStrict && !isTypeStrict) {
|
|
401
|
+
return false;
|
|
400
402
|
}
|
|
403
|
+
return valueStrict ? isValueStrict : true;
|
|
401
404
|
} else {
|
|
402
405
|
return false;
|
|
403
406
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const notRequestError = require("not-error/src/request.error.node.cjs");
|
|
2
|
+
|
|
3
|
+
//delete wasnt successful, or error, or count of deleted documents dont match requested
|
|
4
|
+
class ActionExceptionWrongType extends notRequestError {
|
|
5
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
6
|
+
super("Logic cant run this action", { code: 505, params }, cause);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
module.exports.ActionExceptionWrongType = ActionExceptionWrongType;
|
|
10
|
+
|
|
11
|
+
class ActionExceptionPipeExecutionError extends notRequestError {
|
|
12
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
13
|
+
super(
|
|
14
|
+
"Logic cant run this actions sequence",
|
|
15
|
+
{ code: 505, params },
|
|
16
|
+
cause
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
module.exports.ActionExceptionPipeExecutionError =
|
|
21
|
+
ActionExceptionPipeExecutionError;
|
|
22
|
+
|
|
23
|
+
class OwnageExceptionIdentityUserIdIsNotDefined extends notRequestError {
|
|
24
|
+
constructor(actionName, identity) {
|
|
25
|
+
super(
|
|
26
|
+
"User identity `uid` is not defined, ownage couldnt be determined",
|
|
27
|
+
{ code: 505, params: { actionName, identity } },
|
|
28
|
+
null
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
module.exports.OwnageExceptionIdentityUserIdIsNotDefined =
|
|
33
|
+
OwnageExceptionIdentityUserIdIsNotDefined;
|
|
34
|
+
|
|
35
|
+
class LogicDeleteActionException extends notRequestError {
|
|
36
|
+
constructor(params, cause) {
|
|
37
|
+
super("Logic Delete Action exception", { code: 505, params }, cause);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
module.exports.LogicDeleteActionException = LogicDeleteActionException;
|
|
41
|
+
|
|
42
|
+
class LogicCreateActionException extends notRequestError {
|
|
43
|
+
constructor(params, cause) {
|
|
44
|
+
super("Logic Create Action exception", { code: 505, params }, cause);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
module.exports.LogicCreateActionException = LogicCreateActionException;
|
|
48
|
+
class LogicUpdateActionException extends notRequestError {
|
|
49
|
+
constructor(params, cause) {
|
|
50
|
+
super("Logic Update Action exception", { code: 505, params }, cause);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
module.exports.LogicUpdateActionException = LogicUpdateActionException;
|
|
54
|
+
|
|
55
|
+
class LogicCountActionException extends notRequestError {
|
|
56
|
+
constructor(params, cause) {
|
|
57
|
+
super("Logic Count Action exception", { code: 505, params }, cause);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
module.exports.LogicCountActionException = LogicCountActionException;
|
|
61
|
+
|
|
62
|
+
class LogicListAndCountActionException extends notRequestError {
|
|
63
|
+
constructor(params, cause) {
|
|
64
|
+
super(
|
|
65
|
+
"Logic ListAndCount Action exception",
|
|
66
|
+
{ code: 505, params },
|
|
67
|
+
cause
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
module.exports.LogicListAndCountActionException =
|
|
72
|
+
LogicListAndCountActionException;
|
|
73
|
+
|
|
74
|
+
class LogicGetActionException extends notRequestError {
|
|
75
|
+
constructor(params, cause) {
|
|
76
|
+
super("Logic Get Action exception", { code: 505, params }, cause);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
module.exports.LogicGetActionException = LogicGetActionException;
|
|
80
|
+
|
|
81
|
+
class LogicGetRawActionException extends notRequestError {
|
|
82
|
+
constructor(params, cause) {
|
|
83
|
+
super("Logic GetRaw Action exception", { code: 505, params }, cause);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
module.exports.LogicGetRawActionException = LogicGetRawActionException;
|
|
87
|
+
|
|
88
|
+
class LogicListActionException extends notRequestError {
|
|
89
|
+
constructor(params, cause) {
|
|
90
|
+
super("Logic List Action exception", { code: 505, params }, cause);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
module.exports.LogicListActionException = LogicListActionException;
|
|
94
|
+
|
|
95
|
+
class LogicListAllActionException extends notRequestError {
|
|
96
|
+
constructor(params, cause) {
|
|
97
|
+
super("Logic ListAll Action exception", { code: 505, params }, cause);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
module.exports.LogicListAllActionException = LogicListAllActionException;
|
package/src/exceptions/db.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
const { notRequestError } = require("not-error");
|
|
1
|
+
const { notError, notRequestError } = require("not-error/src/index.cjs");
|
|
2
2
|
|
|
3
3
|
//delete wasnt successful, or error, or count of deleted documents dont match requested
|
|
4
|
-
class DBExceptionDeleteWasNotSuccessful extends
|
|
5
|
-
constructor(
|
|
6
|
-
super("DB Delete Was Not Successful",
|
|
4
|
+
class DBExceptionDeleteWasNotSuccessful extends notError {
|
|
5
|
+
constructor(result) {
|
|
6
|
+
super("DB Delete Was Not Successful", result);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
|
|
9
10
|
module.exports.DBExceptionDeleteWasNotSuccessful =
|
|
10
11
|
DBExceptionDeleteWasNotSuccessful;
|
|
11
12
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const notRequestError = require("not-error/src/request.error.node.cjs");
|
|
2
|
+
|
|
3
|
+
//delete wasnt successful, or error, or count of deleted documents dont match requested
|
|
4
|
+
class LogicExceptionActionExecutionError extends notRequestError {
|
|
5
|
+
constructor(moduleName, modelName, actionName, cause) {
|
|
6
|
+
super(
|
|
7
|
+
"Logic cant run this action",
|
|
8
|
+
{ code: 505, params: { moduleName, modelName, actionName } },
|
|
9
|
+
cause
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
module.exports.LogicExceptionActionExecutionError =
|
|
14
|
+
LogicExceptionActionExecutionError;
|
package/src/generic/logic.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { objHas, isFunc, executeFunctionAsAsync } = require("../common");
|
|
2
2
|
const ModelRoutine = require("../model/routine");
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
const {
|
|
5
5
|
DBExceptionDocumentIsNotFound,
|
|
6
6
|
DBExceptionDeleteWasNotSuccessful,
|
|
@@ -360,7 +360,7 @@ module.exports = ({
|
|
|
360
360
|
let query = { _id: targetId };
|
|
361
361
|
checkShouldOwn(query, shouldOwn, identity);
|
|
362
362
|
const result = await model.findOneAndDelete(query).exec();
|
|
363
|
-
if (!
|
|
363
|
+
if (!result) {
|
|
364
364
|
throw new DBExceptionDeleteWasNotSuccessful({
|
|
365
365
|
params: {
|
|
366
366
|
result,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { ActionExceptionWrongType } = require("../exceptions/action.js");
|
|
2
|
+
|
|
3
|
+
class ActionRunner {
|
|
4
|
+
static async run(action, params) {
|
|
5
|
+
//any static class with static run method
|
|
6
|
+
if (typeof action === "function" && typeof action.run === "function") {
|
|
7
|
+
return await action.run(...params);
|
|
8
|
+
} else if (typeof action === "function") {
|
|
9
|
+
return await action(...params);
|
|
10
|
+
}
|
|
11
|
+
throw new ActionExceptionWrongType();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = ActionRunner;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module.exports = class GetByIDAction {
|
|
2
|
+
static async run(
|
|
3
|
+
logic,
|
|
4
|
+
actionName,
|
|
5
|
+
{ targetID, identity, defaultQueryByID }
|
|
6
|
+
) {
|
|
7
|
+
logic.logDebugAction(actionName, identity);
|
|
8
|
+
|
|
9
|
+
let populate = await logic.getPopulate(actionName, {
|
|
10
|
+
targetID,
|
|
11
|
+
identity,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const result = await logic
|
|
15
|
+
.getModel()
|
|
16
|
+
.getOneByID(targetID, defaultQueryByID, populate);
|
|
17
|
+
logic.logAction(actionName, identity, {
|
|
18
|
+
targetID,
|
|
19
|
+
version: result?.__version,
|
|
20
|
+
});
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = { getByID: require("./getByID.js") };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const ActionsSetsLibrary = require("../actions.lib");
|
|
2
|
+
|
|
3
|
+
let actionsSetsLibrary = new ActionsSetsLibrary();
|
|
4
|
+
|
|
5
|
+
actionsSetsLibrary.add("standart", require("./standart"));
|
|
6
|
+
actionsSetsLibrary.add("increment", require("./increment"));
|
|
7
|
+
|
|
8
|
+
module.exports = actionsSetsLibrary;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { LogicCountActionException } = require("../../../exceptions/action");
|
|
2
|
+
|
|
3
|
+
module.exports = class CountAction {
|
|
4
|
+
static async run(logic, actionName, { identity, query }) {
|
|
5
|
+
try {
|
|
6
|
+
logic.logDebugAction(actionName, identity);
|
|
7
|
+
const { filter, search } = query;
|
|
8
|
+
const result = await logic
|
|
9
|
+
.getModel()
|
|
10
|
+
.countWithFilter(search || filter);
|
|
11
|
+
logic.logAction(actionName, identity);
|
|
12
|
+
return result;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
throw new LogicCountActionException(
|
|
15
|
+
{
|
|
16
|
+
query,
|
|
17
|
+
activeUserId: identity?.uid,
|
|
18
|
+
role: identity?.role,
|
|
19
|
+
},
|
|
20
|
+
e
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { LogicCreateActionException } = require("../../../exceptions/action");
|
|
2
|
+
module.exports = class CreateAction {
|
|
3
|
+
static async run(logic, actionName, { identity, data }) {
|
|
4
|
+
try {
|
|
5
|
+
logic.logDebugAction(actionName, identity);
|
|
6
|
+
const result = await logic.getModel().add(data);
|
|
7
|
+
logic.logAction(actionName, identity, {
|
|
8
|
+
targetId: result?._id,
|
|
9
|
+
});
|
|
10
|
+
return result;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw new LogicCreateActionException(
|
|
13
|
+
{
|
|
14
|
+
activeUserId: identity?.uid,
|
|
15
|
+
role: identity?.role,
|
|
16
|
+
},
|
|
17
|
+
e
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const { LogicDeleteActionException } = require("../../../exceptions/action.js");
|
|
2
|
+
module.exports = class DeleteAction {
|
|
3
|
+
static async run(
|
|
4
|
+
logic,
|
|
5
|
+
actionName,
|
|
6
|
+
{ identity, defaultQueryById, targetId }
|
|
7
|
+
) {
|
|
8
|
+
logic.logDebugAction(actionName, identity);
|
|
9
|
+
/** @type {import('../../../types.js').notAppModel } */
|
|
10
|
+
const model = logic.getModel();
|
|
11
|
+
try {
|
|
12
|
+
await model.removeOne(defaultQueryById);
|
|
13
|
+
logic.logAction(actionName, identity, {
|
|
14
|
+
query: defaultQueryById,
|
|
15
|
+
});
|
|
16
|
+
} catch (e) {
|
|
17
|
+
throw new LogicDeleteActionException(
|
|
18
|
+
{
|
|
19
|
+
targetId,
|
|
20
|
+
query: defaultQueryById,
|
|
21
|
+
activeUserId: identity?.uid,
|
|
22
|
+
role: identity?.role,
|
|
23
|
+
},
|
|
24
|
+
e
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const { LogicGetActionException } = require("../../../exceptions/action");
|
|
2
|
+
|
|
3
|
+
module.exports = class GetAction {
|
|
4
|
+
static async run(
|
|
5
|
+
logic,
|
|
6
|
+
actionName,
|
|
7
|
+
{ identity, defaultQueryById, targetId }
|
|
8
|
+
) {
|
|
9
|
+
try {
|
|
10
|
+
logic.logDebugAction(actionName, identity);
|
|
11
|
+
|
|
12
|
+
let populate = await logic.getPopulate(actionName, {
|
|
13
|
+
targetId,
|
|
14
|
+
identity,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const result = await logic
|
|
18
|
+
.getModel()
|
|
19
|
+
.getOne(targetId, populate, defaultQueryById);
|
|
20
|
+
|
|
21
|
+
logic.logAction(actionName, identity, {
|
|
22
|
+
targetId,
|
|
23
|
+
version: result?.__version,
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
throw new LogicGetActionException(
|
|
28
|
+
{
|
|
29
|
+
targetId,
|
|
30
|
+
query: defaultQueryById,
|
|
31
|
+
activeUserId: identity?.uid,
|
|
32
|
+
role: identity?.role,
|
|
33
|
+
},
|
|
34
|
+
e
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { LogicGetRawActionException } = require("../../../exceptions/action");
|
|
2
|
+
|
|
3
|
+
module.exports = class GetRawAction {
|
|
4
|
+
static async run(
|
|
5
|
+
logic,
|
|
6
|
+
actionName,
|
|
7
|
+
{ identity, defaultQueryById, targetId }
|
|
8
|
+
) {
|
|
9
|
+
try {
|
|
10
|
+
logic.logDebugAction(actionName, identity);
|
|
11
|
+
const result = await logic
|
|
12
|
+
.getModel()
|
|
13
|
+
.getOneRaw(targetId, defaultQueryById);
|
|
14
|
+
logic.logAction(actionName, identity, {
|
|
15
|
+
targetId,
|
|
16
|
+
version: result?.__version,
|
|
17
|
+
});
|
|
18
|
+
return result;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw new LogicGetRawActionException(
|
|
21
|
+
{
|
|
22
|
+
targetId,
|
|
23
|
+
query: defaultQueryById,
|
|
24
|
+
activeUserId: identity?.uid,
|
|
25
|
+
role: identity?.role,
|
|
26
|
+
},
|
|
27
|
+
e
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
count: require("./count.js"),
|
|
3
|
+
create: require("./create.js"),
|
|
4
|
+
delete: require("./delete.js"),
|
|
5
|
+
get: require("./get.js"),
|
|
6
|
+
getRaw: require("./getRaw.js"),
|
|
7
|
+
list: require("./list.js"),
|
|
8
|
+
listAll: require("./listAll.js"),
|
|
9
|
+
listAndCount: require("./listAndCount.js"),
|
|
10
|
+
update: require("./update.js"),
|
|
11
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { LogicListActionException } = require("../../../exceptions/action");
|
|
2
|
+
|
|
3
|
+
module.exports = class ListAction {
|
|
4
|
+
static async run(logic, actionName, { identity, query }) {
|
|
5
|
+
try {
|
|
6
|
+
logic.logDebugAction(actionName, identity);
|
|
7
|
+
const { skip, size, sorter, filter } = query;
|
|
8
|
+
let populate = await logic.getPopulate(actionName, {
|
|
9
|
+
identity,
|
|
10
|
+
});
|
|
11
|
+
const result = await logic
|
|
12
|
+
.getModel()
|
|
13
|
+
.listAndPopulate(skip, size, sorter, filter, populate);
|
|
14
|
+
logic.logAction(actionName, identity, {});
|
|
15
|
+
return result;
|
|
16
|
+
} catch (e) {
|
|
17
|
+
throw new LogicListActionException(
|
|
18
|
+
{
|
|
19
|
+
query,
|
|
20
|
+
activeUserId: identity?.uid,
|
|
21
|
+
role: identity?.role,
|
|
22
|
+
},
|
|
23
|
+
e
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { LogicListAllActionException } = require("../../../exceptions/action");
|
|
2
|
+
|
|
3
|
+
module.exports = class ListAllAction {
|
|
4
|
+
static async run(logic, actionName, { identity, defaultQueryMany }) {
|
|
5
|
+
try {
|
|
6
|
+
logic.logDebugAction(actionName, identity);
|
|
7
|
+
const result = await logic.getModel().listAll(defaultQueryMany);
|
|
8
|
+
logic.logAction(actionName, identity, {});
|
|
9
|
+
return result;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
throw new LogicListAllActionException(
|
|
12
|
+
{
|
|
13
|
+
query: defaultQueryMany,
|
|
14
|
+
activeUserId: identity?.uid,
|
|
15
|
+
role: identity?.role,
|
|
16
|
+
},
|
|
17
|
+
e
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const {
|
|
2
|
+
LogicListAndCountActionException,
|
|
3
|
+
} = require("../../../exceptions/action");
|
|
4
|
+
|
|
5
|
+
module.exports = class ListAndCountAction {
|
|
6
|
+
static async run(logic, actionName, { identity, query }) {
|
|
7
|
+
try {
|
|
8
|
+
logic.logDebugAction(actionName, identity);
|
|
9
|
+
const { skip, size, sorter, filter, search } = query;
|
|
10
|
+
let populate = await logic.getPopulate(actionName, {
|
|
11
|
+
identity,
|
|
12
|
+
});
|
|
13
|
+
const result = await logic
|
|
14
|
+
.getModel()
|
|
15
|
+
.listAndCount(skip, size, sorter, filter, search, populate);
|
|
16
|
+
logic.logAction(actionName, identity, {});
|
|
17
|
+
return result;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw new LogicListAndCountActionException(
|
|
20
|
+
{
|
|
21
|
+
query,
|
|
22
|
+
activeUserId: identity?.uid,
|
|
23
|
+
role: identity?.role,
|
|
24
|
+
},
|
|
25
|
+
e
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { LogicUpdateActionException } = require("../../../exceptions/action");
|
|
2
|
+
module.exports = class UpdateAction {
|
|
3
|
+
static async run(
|
|
4
|
+
logic,
|
|
5
|
+
actionName,
|
|
6
|
+
{ identity, data, targetId, defaultQueryById }
|
|
7
|
+
) {
|
|
8
|
+
try {
|
|
9
|
+
logic.logDebugAction(actionName, identity);
|
|
10
|
+
const result = await logic
|
|
11
|
+
.getModel()
|
|
12
|
+
.update(defaultQueryById, data);
|
|
13
|
+
logic.logAction(actionName, identity, {
|
|
14
|
+
targetId,
|
|
15
|
+
version: result?.__version,
|
|
16
|
+
});
|
|
17
|
+
return result;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw new LogicUpdateActionException(
|
|
20
|
+
{
|
|
21
|
+
targetId,
|
|
22
|
+
query: defaultQueryById,
|
|
23
|
+
activeUserId: identity?.uid,
|
|
24
|
+
role: identity?.role,
|
|
25
|
+
},
|
|
26
|
+
e
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const notFilter = require("not-filter");
|
|
2
|
+
const { DOCUMENT_OWNER_FIELD_NAME } = require("../../../auth/const.js");
|
|
3
|
+
const {
|
|
4
|
+
OwnageExceptionIdentityUserIdIsNotDefined,
|
|
5
|
+
} = require("../../../exceptions/action.js");
|
|
6
|
+
const ModelRoutine = require("../../../model/routine.js");
|
|
7
|
+
|
|
8
|
+
//checks that
|
|
9
|
+
module.exports = class OwnageBeforeAction {
|
|
10
|
+
static #ownerFieldName = DOCUMENT_OWNER_FIELD_NAME;
|
|
11
|
+
|
|
12
|
+
static get ownerFieldName() {
|
|
13
|
+
return this.#ownerFieldName;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static async run(logic, actionName, args) {
|
|
17
|
+
const { identity, data, query, targetId, targetID } = args;
|
|
18
|
+
if (identity.uid) {
|
|
19
|
+
//if searching, counting, listing and so on
|
|
20
|
+
//adding condition of ownership by this excat user
|
|
21
|
+
const { filter, search } = query;
|
|
22
|
+
if (filter) {
|
|
23
|
+
notFilter.filter.modifyRules(filter, {
|
|
24
|
+
[OwnageBeforeAction.ownerFieldName]: identity?.uid,
|
|
25
|
+
});
|
|
26
|
+
if (search) {
|
|
27
|
+
notFilter.filter.modifyRules(search, filter);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
args.defaultQueryById = {
|
|
31
|
+
_id: targetId,
|
|
32
|
+
[OwnageBeforeAction.ownerFieldName]: identity?.uid,
|
|
33
|
+
};
|
|
34
|
+
const Model = logic.getModel();
|
|
35
|
+
const incFieldName = ModelRoutine.incremental(Model);
|
|
36
|
+
if (incFieldName) {
|
|
37
|
+
args.defaultQueryByID = {
|
|
38
|
+
[incFieldName]: targetID,
|
|
39
|
+
[OwnageBeforeAction.ownerFieldName]: identity?.uid,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
args.defaultQueryMany = {
|
|
44
|
+
[OwnageBeforeAction.ownerFieldName]: identity?.uid,
|
|
45
|
+
};
|
|
46
|
+
//mark data as owned by
|
|
47
|
+
if (data) {
|
|
48
|
+
data[OwnageBeforeAction.ownerFieldName] = identity.uid;
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
throw new OwnageExceptionIdentityUserIdIsNotDefined(
|
|
52
|
+
actionName,
|
|
53
|
+
identity
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class ActionsSetsLibrary {
|
|
2
|
+
#lib = new Map();
|
|
3
|
+
|
|
4
|
+
add(name, set) {
|
|
5
|
+
if (!this.#lib.has(name)) {
|
|
6
|
+
this.#lib.set(name, set);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get(name) {
|
|
11
|
+
if (this.#lib.has(name)) {
|
|
12
|
+
return this.#lib.get(name);
|
|
13
|
+
}
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = ActionsSetsLibrary;
|