c2-mongoose 2.1.267 → 2.1.269
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/package.json +1 -1
- package/src/flow/C2Flow.ts +22 -0
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
|
+
updateByFilters(filters: any, data: D, options: Partial<Options>): Promise<any>;
|
|
11
12
|
updateMany(searcher: SearchFlow, data: D, options: Options): Promise<any>;
|
|
12
13
|
deleteById(_id: Types.ObjectId, options: Partial<Options>): Promise<void>;
|
|
13
14
|
deleteByModel(searcher: SearchFlow, options: Partial<Options>): Promise<void>;
|
package/dist/flow/C2Flow.js
CHANGED
|
@@ -155,6 +155,35 @@ var C2Flow = /** @class */ (function () {
|
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
157
|
};
|
|
158
|
+
C2Flow.prototype.updateByFilters = function (filters, 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(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: 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.updateMany = function (searcher, data, options) {
|
|
159
188
|
return __awaiter(this, void 0, void 0, function () {
|
|
160
189
|
var dataAfter, log;
|
package/package.json
CHANGED
package/src/flow/C2Flow.ts
CHANGED
|
@@ -83,6 +83,28 @@ class C2Flow<D> {
|
|
|
83
83
|
return dataAfter._doc
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
async updateByFilters(filters: any, data: D, options: Partial<Options>): Promise<any> {
|
|
87
|
+
let dataAfter = await this.repository.updateMany(filters, data as any, { returnDocument: 'after', session: options.session })
|
|
88
|
+
|
|
89
|
+
if (options.logger === false) {
|
|
90
|
+
if (isEmpty(dataAfter)) {
|
|
91
|
+
return dataAfter
|
|
92
|
+
}
|
|
93
|
+
return dataAfter
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (isEmpty(dataAfter)) {
|
|
97
|
+
return dataAfter
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, { filters, ...data }, TypeOfOperation.UPDATE, this.repository)
|
|
101
|
+
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
102
|
+
if (isEmpty(dataAfter)) {
|
|
103
|
+
return dataAfter
|
|
104
|
+
}
|
|
105
|
+
return dataAfter
|
|
106
|
+
}
|
|
107
|
+
|
|
86
108
|
async updateMany(searcher: SearchFlow, data: D, options: Options): Promise<any> {
|
|
87
109
|
let dataAfter = await this.repository.updateMany(searcher.filters, data as Partial<D>, { returnDocument: 'after', session: options.session })
|
|
88
110
|
if (options.logger === false) {
|