c2-mongoose 2.1.239 → 2.1.241
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/dist/flow/C2Flow.d.ts +1 -0
- package/dist/flow/C2Flow.js +29 -0
- package/dist/flow/item/BuildPopulateSingleFlowItem.d.ts +1 -1
- package/dist/flow/item/BuildPopulateSingleFlowItem.js +30 -18
- package/dist/model/Logger.d.ts +8 -0
- package/dist/model/Logger.js +3 -1
- package/package.json +1 -1
- package/src/flow/C2Flow.ts +22 -1
- package/src/flow/item/BuildPopulateSingleFlowItem.ts +34 -18
- package/src/model/Logger.ts +5 -1
package/dist/flow/C2Flow.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare class C2Flow<D> {
|
|
|
8
8
|
createMany(data: Partial<D>[], options: Partial<Options>): Promise<Partial<D>[]>;
|
|
9
9
|
updateById(_id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
10
10
|
updateByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
11
|
+
updateMany(searcher: SearchFlow, data: D, options: Options): Promise<any>;
|
|
11
12
|
deleteById(_id: Types.ObjectId, options: Partial<Options>): Promise<void>;
|
|
12
13
|
deleteByModel(searcher: SearchFlow, options: Partial<Options>): Promise<void>;
|
|
13
14
|
}
|
package/dist/flow/C2Flow.js
CHANGED
|
@@ -155,6 +155,35 @@ var C2Flow = /** @class */ (function () {
|
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
157
|
};
|
|
158
|
+
C2Flow.prototype.updateMany = function (searcher, data, options) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
var dataAfter, log;
|
|
161
|
+
return __generator(this, function (_a) {
|
|
162
|
+
switch (_a.label) {
|
|
163
|
+
case 0: return [4 /*yield*/, this.repository.updateMany(searcher.filters, data, { returnDocument: 'after', session: options.session })];
|
|
164
|
+
case 1:
|
|
165
|
+
dataAfter = _a.sent();
|
|
166
|
+
if (options.logger === false) {
|
|
167
|
+
if ((0, Utils_1.isEmpty)(dataAfter)) {
|
|
168
|
+
return [2 /*return*/, dataAfter];
|
|
169
|
+
}
|
|
170
|
+
return [2 /*return*/, dataAfter];
|
|
171
|
+
}
|
|
172
|
+
if ((0, Utils_1.isEmpty)(dataAfter)) {
|
|
173
|
+
return [2 /*return*/, dataAfter];
|
|
174
|
+
}
|
|
175
|
+
log = BuildLogFlowItem_1.default.build(options, __assign({ filters: searcher.filters }, data), Logger_1.TypeOfOperation.UPDATE, this.repository);
|
|
176
|
+
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
|
|
177
|
+
case 2:
|
|
178
|
+
_a.sent();
|
|
179
|
+
if ((0, Utils_1.isEmpty)(dataAfter)) {
|
|
180
|
+
return [2 /*return*/, dataAfter];
|
|
181
|
+
}
|
|
182
|
+
return [2 /*return*/, dataAfter];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
};
|
|
158
187
|
C2Flow.prototype.deleteById = function (_id, options) {
|
|
159
188
|
return __awaiter(this, void 0, void 0, function () {
|
|
160
189
|
var dataAfter, log;
|
|
@@ -2,7 +2,7 @@ import mongoose from "mongoose";
|
|
|
2
2
|
import { IPopulate } from "../SearcherFlow";
|
|
3
3
|
declare class BuildPopulateSingleFlowItem {
|
|
4
4
|
buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[];
|
|
5
|
-
buildPath(target: string, nested
|
|
5
|
+
buildPath(target: string, nested: string | undefined, populateAcc: IPopulate): IPopulate;
|
|
6
6
|
}
|
|
7
7
|
declare const _default: BuildPopulateSingleFlowItem;
|
|
8
8
|
export default _default;
|
|
@@ -16,15 +16,16 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
|
|
|
16
16
|
function BuildPopulateSingleFlowItem() {
|
|
17
17
|
}
|
|
18
18
|
BuildPopulateSingleFlowItem.prototype.buildPopulate = function (model, populatesStr, selectsStr) {
|
|
19
|
-
var _a
|
|
20
|
-
var
|
|
19
|
+
var _a;
|
|
20
|
+
var populateArray = [];
|
|
21
21
|
if ((0, Utils_1.isEmpty)(populatesStr)) {
|
|
22
22
|
return [];
|
|
23
23
|
}
|
|
24
24
|
var _loop_1 = function () {
|
|
25
|
-
var
|
|
25
|
+
var _b = property.split('.'), first = _b[0], rest = _b.slice(1);
|
|
26
26
|
var nested = rest.join('.');
|
|
27
|
-
var
|
|
27
|
+
var existing2 = (_a = populateArray.find(function (populateAux) { return populateAux.path === first; })) !== null && _a !== void 0 ? _a : { path: '', populate: {} };
|
|
28
|
+
var populateLocal = this_1.buildPath(first, nested, existing2);
|
|
28
29
|
//EXISTE UMA LIMITACAO DE SELECT A PARTIR DO 3 NIVEL DENTRO DOS CAMPO POPULATE, MELHORAR O CODIGO ABAIXO PARA PERCORRER MAIS NIVEIS
|
|
29
30
|
if (Array.isArray(selectsStr)) {
|
|
30
31
|
var allSelectOfPopulate = selectsStr.filter(function (sel) { return sel.startsWith("".concat(first, ".").concat(populateLocal.path)); });
|
|
@@ -35,31 +36,42 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
//FIM
|
|
38
|
-
|
|
39
|
-
if (existing) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
39
|
+
// const existing = populateArray.find((populateAux: IPopulate) => populateAux.path === populateLocal.path)
|
|
40
|
+
// if (existing) {
|
|
41
|
+
// if (populateLocal.populate && existing.populate){
|
|
42
|
+
// if (!existing.populate.path.includes(populateLocal.populate.path)){
|
|
43
|
+
// existing.populate.path += populateLocal.populate.path
|
|
44
|
+
// }
|
|
45
|
+
// }
|
|
46
|
+
// const populateAux = {
|
|
47
|
+
// ...existing?.populate,
|
|
48
|
+
// path: `${existing.populate?.path ?? ``} ${populateLocal.populate?.path ?? ``}`.trim()
|
|
49
|
+
// }
|
|
50
|
+
// existing.populate = populateAux
|
|
51
|
+
// continue
|
|
52
|
+
// }
|
|
53
|
+
populateArray.push(populateLocal);
|
|
45
54
|
};
|
|
46
55
|
var this_1 = this;
|
|
47
56
|
for (var _i = 0, populatesStr_1 = populatesStr; _i < populatesStr_1.length; _i++) {
|
|
48
57
|
var property = populatesStr_1[_i];
|
|
49
58
|
_loop_1();
|
|
50
59
|
}
|
|
51
|
-
return
|
|
60
|
+
return populateArray;
|
|
52
61
|
};
|
|
53
|
-
BuildPopulateSingleFlowItem.prototype.buildPath = function (target, nested) {
|
|
62
|
+
BuildPopulateSingleFlowItem.prototype.buildPath = function (target, nested, populateAcc) {
|
|
63
|
+
// var populate = {} as IPopulate
|
|
64
|
+
var _a;
|
|
54
65
|
if (nested === void 0) { nested = ""; }
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
if (!((_a = populateAcc.path) === null || _a === void 0 ? void 0 : _a.includes(target))) {
|
|
67
|
+
populateAcc.path += " ".concat(target);
|
|
68
|
+
}
|
|
57
69
|
if ((0, Utils_1.isNotEmpty)(nested)) {
|
|
58
|
-
var
|
|
70
|
+
var _b = nested.split('.'), first = _b[0], rest = _b.slice(1);
|
|
59
71
|
var nested2 = rest.join('.');
|
|
60
|
-
|
|
72
|
+
populateAcc.populate = __assign(__assign({}, populateAcc.populate), this.buildPath(first, nested2, populateAcc.populate));
|
|
61
73
|
}
|
|
62
|
-
return
|
|
74
|
+
return populateAcc;
|
|
63
75
|
};
|
|
64
76
|
return BuildPopulateSingleFlowItem;
|
|
65
77
|
}());
|
package/dist/model/Logger.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ interface ILogger {
|
|
|
13
13
|
createdAtDateTime: moment.Moment;
|
|
14
14
|
operation: TypeOfOperation;
|
|
15
15
|
data: any;
|
|
16
|
+
filters: any;
|
|
17
|
+
notes: string;
|
|
16
18
|
}
|
|
17
19
|
declare const LoggerModel: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.ResolveSchemaOptions<{
|
|
18
20
|
timestamps: {
|
|
@@ -25,18 +27,24 @@ declare const LoggerModel: mongoose.Schema<any, mongoose.Model<any, any, any, an
|
|
|
25
27
|
collectionName: string;
|
|
26
28
|
operation: string;
|
|
27
29
|
data?: any;
|
|
30
|
+
filters?: any;
|
|
31
|
+
notes?: string | undefined;
|
|
28
32
|
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
29
33
|
owner: Types.ObjectId;
|
|
30
34
|
user: Types.ObjectId;
|
|
31
35
|
collectionName: string;
|
|
32
36
|
operation: string;
|
|
33
37
|
data?: any;
|
|
38
|
+
filters?: any;
|
|
39
|
+
notes?: string | undefined;
|
|
34
40
|
}>> & Omit<mongoose.FlatRecord<{
|
|
35
41
|
owner: Types.ObjectId;
|
|
36
42
|
user: Types.ObjectId;
|
|
37
43
|
collectionName: string;
|
|
38
44
|
operation: string;
|
|
39
45
|
data?: any;
|
|
46
|
+
filters?: any;
|
|
47
|
+
notes?: string | undefined;
|
|
40
48
|
}> & {
|
|
41
49
|
_id: Types.ObjectId;
|
|
42
50
|
}, never>>;
|
package/dist/model/Logger.js
CHANGED
|
@@ -57,7 +57,9 @@ var LoggerModel = new mongoose_1.Schema({
|
|
|
57
57
|
user: { type: mongoose_1.default.Schema.Types.ObjectId, required: true, immutable: true },
|
|
58
58
|
collectionName: { type: String, required: true, immutable: true },
|
|
59
59
|
operation: { type: String, enum: TypeOfOperation, required: true, immutable: true },
|
|
60
|
-
data: { type: mongoose_1.default.Schema.Types.Mixed, immutable: true }
|
|
60
|
+
data: { type: mongoose_1.default.Schema.Types.Mixed, immutable: true },
|
|
61
|
+
filters: { type: mongoose_1.default.Schema.Types.Mixed, immutable: true },
|
|
62
|
+
notes: { type: String, immutable: true }
|
|
61
63
|
}, {
|
|
62
64
|
timestamps: { createdAt: 'createdAtDateTime', updatedAt: 'updatedAtDateTime' }
|
|
63
65
|
});
|
package/package.json
CHANGED
package/src/flow/C2Flow.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import mongoose, { Types } from "mongoose"
|
|
2
|
+
import mongoose, { QueryWithHelpers, Types, UpdateWriteOpResult } from "mongoose"
|
|
3
3
|
import { ILogger, TypeOfOperation } from "../model/Logger"
|
|
4
4
|
import { Options } from "../types/Options"
|
|
5
5
|
import BuildLogFlowItem from "./item/BuildLogFlowItem"
|
|
@@ -83,6 +83,27 @@ class C2Flow<D> {
|
|
|
83
83
|
return dataAfter._doc
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
async updateMany(searcher: SearchFlow, data: D, options: Options): Promise<any> {
|
|
87
|
+
let dataAfter = await this.repository.updateMany(searcher.filters, data as Partial<D>, { returnDocument: 'after', session: options.session })
|
|
88
|
+
if (options.logger === false) {
|
|
89
|
+
if (isEmpty(dataAfter)) {
|
|
90
|
+
return dataAfter
|
|
91
|
+
}
|
|
92
|
+
return dataAfter
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (isEmpty(dataAfter)) {
|
|
96
|
+
return dataAfter
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, { filters: searcher.filters, ...data }, TypeOfOperation.UPDATE, this.repository)
|
|
100
|
+
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
101
|
+
if (isEmpty(dataAfter)) {
|
|
102
|
+
return dataAfter
|
|
103
|
+
}
|
|
104
|
+
return dataAfter
|
|
105
|
+
}
|
|
106
|
+
|
|
86
107
|
|
|
87
108
|
public async deleteById(_id: Types.ObjectId, options: Partial<Options>) {
|
|
88
109
|
|
|
@@ -5,7 +5,7 @@ import { IPopulate } from "../SearcherFlow";
|
|
|
5
5
|
class BuildPopulateSingleFlowItem {
|
|
6
6
|
|
|
7
7
|
public buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[] {
|
|
8
|
-
var
|
|
8
|
+
var populateArray = [] as IPopulate[]
|
|
9
9
|
if (isEmpty(populatesStr)) {
|
|
10
10
|
return []
|
|
11
11
|
}
|
|
@@ -14,7 +14,9 @@ class BuildPopulateSingleFlowItem {
|
|
|
14
14
|
let [first, ...rest] = property.split('.')
|
|
15
15
|
let nested = rest.join('.')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const existing2 = populateArray.find((populateAux: IPopulate) => populateAux.path === first) ?? { path: '', populate: {} }
|
|
18
|
+
|
|
19
|
+
let populateLocal = this.buildPath(first, nested, existing2 as IPopulate)
|
|
18
20
|
|
|
19
21
|
//EXISTE UMA LIMITACAO DE SELECT A PARTIR DO 3 NIVEL DENTRO DOS CAMPO POPULATE, MELHORAR O CODIGO ABAIXO PARA PERCORRER MAIS NIVEIS
|
|
20
22
|
if (Array.isArray(selectsStr)) {
|
|
@@ -27,31 +29,45 @@ class BuildPopulateSingleFlowItem {
|
|
|
27
29
|
}
|
|
28
30
|
//FIM
|
|
29
31
|
|
|
30
|
-
const existing =
|
|
31
|
-
if (existing) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
32
|
+
// const existing = populateArray.find((populateAux: IPopulate) => populateAux.path === populateLocal.path)
|
|
33
|
+
// if (existing) {
|
|
34
|
+
|
|
35
|
+
// if (populateLocal.populate && existing.populate){
|
|
36
|
+
// if (!existing.populate.path.includes(populateLocal.populate.path)){
|
|
37
|
+
// existing.populate.path += populateLocal.populate.path
|
|
38
|
+
// }
|
|
39
|
+
// }
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
// const populateAux = {
|
|
42
|
+
// ...existing?.populate,
|
|
43
|
+
// path: `${existing.populate?.path ?? ``} ${populateLocal.populate?.path ?? ``}`.trim()
|
|
44
|
+
// }
|
|
45
|
+
// existing.populate = populateAux
|
|
46
|
+
// continue
|
|
47
|
+
// }
|
|
48
|
+
|
|
49
|
+
populateArray.push(populateLocal)
|
|
41
50
|
}
|
|
42
51
|
|
|
43
|
-
return
|
|
52
|
+
return populateArray
|
|
44
53
|
}
|
|
45
54
|
|
|
46
|
-
public buildPath(target: string, nested: string = ""): IPopulate {
|
|
47
|
-
var populate = {} as IPopulate
|
|
48
|
-
|
|
55
|
+
public buildPath(target: string, nested: string = "", populateAcc: IPopulate): IPopulate {
|
|
56
|
+
// var populate = {} as IPopulate
|
|
57
|
+
|
|
58
|
+
if (!populateAcc.path?.includes(target)){
|
|
59
|
+
populateAcc.path += ` ${target}`
|
|
60
|
+
}
|
|
61
|
+
|
|
49
62
|
if (isNotEmpty(nested)) {
|
|
50
63
|
let [first, ...rest] = nested.split('.')
|
|
51
64
|
let nested2 = rest.join('.')
|
|
52
|
-
|
|
65
|
+
populateAcc.populate = {
|
|
66
|
+
...populateAcc.populate,
|
|
67
|
+
...this.buildPath(first, nested2, populateAcc.populate)
|
|
68
|
+
}
|
|
53
69
|
}
|
|
54
|
-
return
|
|
70
|
+
return populateAcc
|
|
55
71
|
}
|
|
56
72
|
}
|
|
57
73
|
|
package/src/model/Logger.ts
CHANGED
|
@@ -16,6 +16,8 @@ interface ILogger {
|
|
|
16
16
|
createdAtDateTime: moment.Moment
|
|
17
17
|
operation: TypeOfOperation
|
|
18
18
|
data: any
|
|
19
|
+
filters: any
|
|
20
|
+
notes: string
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
const LoggerModel = new Schema({
|
|
@@ -23,7 +25,9 @@ const LoggerModel = new Schema({
|
|
|
23
25
|
user: { type: mongoose.Schema.Types.ObjectId, required: true, immutable: true },
|
|
24
26
|
collectionName: { type: String, required: true, immutable: true },
|
|
25
27
|
operation: { type: String, enum: TypeOfOperation, required: true, immutable: true },
|
|
26
|
-
data: { type: mongoose.Schema.Types.Mixed, immutable: true }
|
|
28
|
+
data: { type: mongoose.Schema.Types.Mixed, immutable: true },
|
|
29
|
+
filters: { type: mongoose.Schema.Types.Mixed, immutable: true },
|
|
30
|
+
notes: { type: String, immutable: true }
|
|
27
31
|
}, {
|
|
28
32
|
timestamps: { createdAt: 'createdAtDateTime', updatedAt: 'updatedAtDateTime' }
|
|
29
33
|
})
|