c2-mongoose 2.1.266 → 2.1.268
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 +2 -0
- package/dist/flow/C2Flow.js +49 -0
- package/package.json +1 -1
- package/src/flow/C2Flow.ts +34 -0
package/dist/flow/C2Flow.d.ts
CHANGED
|
@@ -8,8 +8,10 @@ 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: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
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>;
|
|
15
|
+
deleteByFilters(filters: any, options: Partial<Options>): Promise<void>;
|
|
14
16
|
}
|
|
15
17
|
export default C2Flow;
|
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.findOneAndUpdate(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._doc];
|
|
171
|
+
}
|
|
172
|
+
if ((0, Utils_1.isEmpty)(dataAfter)) {
|
|
173
|
+
return [2 /*return*/, dataAfter];
|
|
174
|
+
}
|
|
175
|
+
log = BuildLogFlowItem_1.default.build(options, __assign({ _id: dataAfter._id }, 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._doc];
|
|
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;
|
|
@@ -224,6 +253,26 @@ var C2Flow = /** @class */ (function () {
|
|
|
224
253
|
});
|
|
225
254
|
});
|
|
226
255
|
};
|
|
256
|
+
C2Flow.prototype.deleteByFilters = function (filters, options) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
var dataAfter, log;
|
|
259
|
+
return __generator(this, function (_a) {
|
|
260
|
+
switch (_a.label) {
|
|
261
|
+
case 0: return [4 /*yield*/, this.repository.deleteMany(filters).session(options.session)];
|
|
262
|
+
case 1:
|
|
263
|
+
dataAfter = _a.sent();
|
|
264
|
+
if (options.logger === false) {
|
|
265
|
+
return [2 /*return*/];
|
|
266
|
+
}
|
|
267
|
+
log = BuildLogFlowItem_1.default.build(options, __assign(__assign({}, filters), dataAfter), Logger_1.TypeOfOperation.DELETE, this.repository);
|
|
268
|
+
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
|
|
269
|
+
case 2:
|
|
270
|
+
_a.sent();
|
|
271
|
+
return [2 /*return*/];
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
};
|
|
227
276
|
return C2Flow;
|
|
228
277
|
}());
|
|
229
278
|
exports.default = C2Flow;
|
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: Partial<D>, options: Partial<Options>): Promise<Partial<D>> {
|
|
87
|
+
let dataAfter = await this.repository.findOneAndUpdate(filters, data, { returnDocument: 'after', session: options.session })
|
|
88
|
+
|
|
89
|
+
if (options.logger === false) {
|
|
90
|
+
if (isEmpty(dataAfter)) {
|
|
91
|
+
return dataAfter
|
|
92
|
+
}
|
|
93
|
+
return dataAfter._doc
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (isEmpty(dataAfter)) {
|
|
97
|
+
return dataAfter
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, { _id: dataAfter._id, ...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._doc
|
|
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) {
|
|
@@ -128,6 +150,18 @@ class C2Flow<D> {
|
|
|
128
150
|
let log: Partial<ILogger> = BuildLogFlowItem.build(options, { ...searcher.filters, ...dataAfter }, TypeOfOperation.DELETE, this.repository)
|
|
129
151
|
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
130
152
|
}
|
|
153
|
+
|
|
154
|
+
public async deleteByFilters(filters: any, options: Partial<Options>) {
|
|
155
|
+
|
|
156
|
+
let dataAfter = await this.repository.deleteMany(filters).session(options.session!)
|
|
157
|
+
|
|
158
|
+
if (options.logger === false) {
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, { ...filters, ...dataAfter }, TypeOfOperation.DELETE, this.repository)
|
|
163
|
+
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
164
|
+
}
|
|
131
165
|
}
|
|
132
166
|
|
|
133
167
|
export default C2Flow
|