not-node 5.1.27 → 5.1.28
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/generic/logic.js +119 -0
- package/src/generic/route.js +18 -0
- package/src/model/increment.js +2 -2
- package/src/model/routine.js +10 -10
- package/src/model/utils.js +1 -1
- package/test/model/default.js +950 -810
- package/test/model/routine.js +178 -175
- package/test/module/fields.js +169 -157
- package/test/module/index.js +52 -52
package/package.json
CHANGED
package/src/generic/logic.js
CHANGED
|
@@ -619,5 +619,124 @@ module.exports = ({
|
|
|
619
619
|
shouldOwn: true,
|
|
620
620
|
});
|
|
621
621
|
}
|
|
622
|
+
|
|
623
|
+
static async _list({
|
|
624
|
+
query,
|
|
625
|
+
activeUser,
|
|
626
|
+
ip,
|
|
627
|
+
action,
|
|
628
|
+
root,
|
|
629
|
+
shouldOwn = false,
|
|
630
|
+
}) {
|
|
631
|
+
Log.debug(
|
|
632
|
+
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
633
|
+
ip,
|
|
634
|
+
root
|
|
635
|
+
);
|
|
636
|
+
const { skip, size, sorter, filter } = query;
|
|
637
|
+
let populate = getPopulate(action, {
|
|
638
|
+
activeUser,
|
|
639
|
+
ip,
|
|
640
|
+
});
|
|
641
|
+
if (shouldOwn) {
|
|
642
|
+
notFilter.filter.modifyRules(filter, {
|
|
643
|
+
[ownerFieldName]: activeUser._id,
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
const result = await getModel().listAndPopulate(
|
|
647
|
+
skip,
|
|
648
|
+
size,
|
|
649
|
+
sorter,
|
|
650
|
+
filter,
|
|
651
|
+
populate
|
|
652
|
+
);
|
|
653
|
+
LogAction({
|
|
654
|
+
action,
|
|
655
|
+
by: activeUser._id,
|
|
656
|
+
role: activeUser.role,
|
|
657
|
+
ip,
|
|
658
|
+
root,
|
|
659
|
+
shouldOwn,
|
|
660
|
+
});
|
|
661
|
+
return result;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
static async list({ query, activeUser, ip, root }) {
|
|
665
|
+
return await this._list({
|
|
666
|
+
query,
|
|
667
|
+
activeUser,
|
|
668
|
+
ip,
|
|
669
|
+
root,
|
|
670
|
+
action: "list",
|
|
671
|
+
shouldOwn: false,
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
static async listOwn({ query, activeUser, ip, root }) {
|
|
676
|
+
return await this._list({
|
|
677
|
+
query,
|
|
678
|
+
activeUser,
|
|
679
|
+
ip,
|
|
680
|
+
root,
|
|
681
|
+
action: "listOwn",
|
|
682
|
+
shouldOwn: true,
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
static async _count({
|
|
687
|
+
query,
|
|
688
|
+
activeUser,
|
|
689
|
+
ip,
|
|
690
|
+
action,
|
|
691
|
+
root,
|
|
692
|
+
shouldOwn = false,
|
|
693
|
+
}) {
|
|
694
|
+
Log.debug(
|
|
695
|
+
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
696
|
+
ip,
|
|
697
|
+
root
|
|
698
|
+
);
|
|
699
|
+
const { filter, search } = query;
|
|
700
|
+
if (shouldOwn) {
|
|
701
|
+
notFilter.filter.modifyRules(filter, {
|
|
702
|
+
[ownerFieldName]: activeUser._id,
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
if (search) {
|
|
706
|
+
notFilter.filter.modifyRules(search, filter);
|
|
707
|
+
}
|
|
708
|
+
const result = await getModel().countWithFilter(search || filter);
|
|
709
|
+
LogAction({
|
|
710
|
+
action,
|
|
711
|
+
by: activeUser._id,
|
|
712
|
+
role: activeUser.role,
|
|
713
|
+
ip,
|
|
714
|
+
root,
|
|
715
|
+
shouldOwn,
|
|
716
|
+
});
|
|
717
|
+
return result;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
static async count({ query, activeUser, ip, root }) {
|
|
721
|
+
return await this._count({
|
|
722
|
+
query,
|
|
723
|
+
activeUser,
|
|
724
|
+
ip,
|
|
725
|
+
root,
|
|
726
|
+
action: "count",
|
|
727
|
+
shouldOwn: false,
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
static async countOwn({ query, activeUser, ip, root }) {
|
|
732
|
+
return await this._count({
|
|
733
|
+
query,
|
|
734
|
+
activeUser,
|
|
735
|
+
ip,
|
|
736
|
+
root,
|
|
737
|
+
action: "countOwn",
|
|
738
|
+
shouldOwn: true,
|
|
739
|
+
});
|
|
740
|
+
}
|
|
622
741
|
};
|
|
623
742
|
};
|
package/src/generic/route.js
CHANGED
|
@@ -62,6 +62,24 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
62
62
|
return await getLogic().listAndCountOwn(prepared);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
static async _list(req, res, next, prepared) {
|
|
66
|
+
prepared.root = true;
|
|
67
|
+
return await getLogic().list(prepared);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async list(req, res, next, prepared) {
|
|
71
|
+
return await getLogic().listOwn(prepared);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static async _count(req, res, next, prepared) {
|
|
75
|
+
prepared.root = true;
|
|
76
|
+
return await getLogic().count(prepared);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static async count(req, res, next, prepared) {
|
|
80
|
+
return await getLogic().countOwn(prepared);
|
|
81
|
+
}
|
|
82
|
+
|
|
65
83
|
static async _delete(req, res, next, prepared) {
|
|
66
84
|
prepared.root = true;
|
|
67
85
|
return await getLogic().delete(prepared);
|
package/src/model/increment.js
CHANGED
|
@@ -59,9 +59,9 @@ module.exports.formId = formId;
|
|
|
59
59
|
**/
|
|
60
60
|
function secureUpdate(thisModel, which, cmd, opts) {
|
|
61
61
|
if (typeof thisModel.updateOne === "function") {
|
|
62
|
-
return thisModel.updateOne(which, cmd, opts)
|
|
62
|
+
return thisModel.updateOne(which, cmd, opts);
|
|
63
63
|
} else {
|
|
64
|
-
return thisModel.update(which, cmd, opts)
|
|
64
|
+
return thisModel.update(which, cmd, opts);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
package/src/model/routine.js
CHANGED
|
@@ -45,6 +45,7 @@ class ModelRoutine {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
static async update(model, filter, data) {
|
|
48
|
+
if ("_id" in data) delete data._id;
|
|
48
49
|
if (ModelRoutine.versioning(model)) {
|
|
49
50
|
return ModelRoutine.updateWithVersion(model, filter, data);
|
|
50
51
|
} else {
|
|
@@ -64,9 +65,9 @@ class ModelRoutine {
|
|
|
64
65
|
static async updateWithVersion(model, filter, data) {
|
|
65
66
|
filter.__latest = true;
|
|
66
67
|
filter.__closed = false;
|
|
67
|
-
const result = await model
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
const result = await model.updateOne(filter, data, {
|
|
69
|
+
returnOriginal: false,
|
|
70
|
+
});
|
|
70
71
|
if (updateResponseSuccess(result, 1)) {
|
|
71
72
|
return model.saveVersion(filter._id);
|
|
72
73
|
} else {
|
|
@@ -75,6 +76,7 @@ class ModelRoutine {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
static async updateMany(model, filter, data) {
|
|
79
|
+
if ("_id" in data) delete data._id;
|
|
78
80
|
if (ModelRoutine.versioning(model)) {
|
|
79
81
|
return ModelRoutine.updateManyWithVersion(model, filter, data);
|
|
80
82
|
} else {
|
|
@@ -87,13 +89,11 @@ class ModelRoutine {
|
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
static async updateManyWithVersion(model, filter, data) {
|
|
90
|
-
const list = await model
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
})
|
|
96
|
-
.exec();
|
|
92
|
+
const list = await model.find({
|
|
93
|
+
__closed: false,
|
|
94
|
+
__latest: true,
|
|
95
|
+
...filter,
|
|
96
|
+
});
|
|
97
97
|
return await Promise.allSettled(
|
|
98
98
|
list.map((item) => {
|
|
99
99
|
return ModelRoutine.updateWithVersion(
|
package/src/model/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ function updateResponseSuccess(res, count = 1) {
|
|
|
7
7
|
if (responseList.includes("ok")) {
|
|
8
8
|
return res.ok === 1 && res.n === count;
|
|
9
9
|
} else {
|
|
10
|
-
return res.matchedCount === count && res.
|
|
10
|
+
return res.matchedCount === count && res.acknowledged;
|
|
11
11
|
}
|
|
12
12
|
} else {
|
|
13
13
|
return false;
|