c2-mongoose 2.1.134 → 2.1.136
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 +20 -0
- package/dist/flow/SearchFlow.js +5 -2
- package/package.json +1 -1
- package/src/flow/C2Flow.ts +13 -0
- package/src/flow/SearchFlow.ts +5 -3
package/dist/flow/C2Flow.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare class C2Flow<D> {
|
|
|
5
5
|
private repository;
|
|
6
6
|
constructor(repository: mongoose.Model<any>);
|
|
7
7
|
create(data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
8
|
+
createMany(data: Partial<D>[], options: Partial<Options>): Promise<Partial<D>>;
|
|
8
9
|
updateById(_id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
9
10
|
updateByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
10
11
|
deleteById(_id: Types.ObjectId, options: Partial<Options>): Promise<void>;
|
package/dist/flow/C2Flow.js
CHANGED
|
@@ -76,6 +76,26 @@ var C2Flow = /** @class */ (function () {
|
|
|
76
76
|
});
|
|
77
77
|
});
|
|
78
78
|
};
|
|
79
|
+
C2Flow.prototype.createMany = function (data, options) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var dataAfter, log;
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
84
|
+
case 0: return [4 /*yield*/, this.repository.create(data, { session: options.session })];
|
|
85
|
+
case 1:
|
|
86
|
+
dataAfter = _a.sent();
|
|
87
|
+
if (options.logger === false) {
|
|
88
|
+
return [2 /*return*/, dataAfter[0]._doc];
|
|
89
|
+
}
|
|
90
|
+
log = BuildLogFlowItem_1.default.build(options, dataAfter[0]._doc, Logger_1.TypeOfOperation.CREATE, this.repository);
|
|
91
|
+
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
|
|
92
|
+
case 2:
|
|
93
|
+
_a.sent();
|
|
94
|
+
return [2 /*return*/, dataAfter[0]._doc];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
79
99
|
C2Flow.prototype.updateById = function (_id, data, options) {
|
|
80
100
|
return __awaiter(this, void 0, void 0, function () {
|
|
81
101
|
var dataAfter, log;
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -75,9 +75,12 @@ var SearchFlow = /** @class */ (function () {
|
|
|
75
75
|
var found = false;
|
|
76
76
|
for (var _i = 0, _a = this.select; _i < _a.length; _i++) {
|
|
77
77
|
var field = _a[_i];
|
|
78
|
-
if (field.
|
|
78
|
+
if (field.startsWith("-")) {
|
|
79
|
+
field = field.substring(1);
|
|
80
|
+
projection[field] = -1;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
79
83
|
projection[field] = 1;
|
|
80
|
-
found = true;
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
if (found)
|
package/package.json
CHANGED
package/src/flow/C2Flow.ts
CHANGED
|
@@ -26,6 +26,19 @@ class C2Flow<D> {
|
|
|
26
26
|
return dataAfter[0]._doc
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
async createMany(data: Partial<D>[], options: Partial<Options>): Promise<Partial<D>> {
|
|
30
|
+
let dataAfter = await this.repository.create(data, { session: options.session })
|
|
31
|
+
|
|
32
|
+
if (options.logger === false) {
|
|
33
|
+
return dataAfter[0]._doc
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, dataAfter[0]._doc, TypeOfOperation.CREATE, this.repository)
|
|
37
|
+
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
38
|
+
|
|
39
|
+
return dataAfter[0]._doc
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
async updateById(_id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>> {
|
|
30
43
|
let dataAfter = await this.repository.findByIdAndUpdate(_id, data, { returnDocument: 'after', session: options.session })
|
|
31
44
|
|
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -38,9 +38,11 @@ abstract class SearchFlow {
|
|
|
38
38
|
let projection: { [key: string]: number } = {}
|
|
39
39
|
let found = false
|
|
40
40
|
for (var field of this.select) {
|
|
41
|
-
if (field.
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
if (field.startsWith("-")) {
|
|
42
|
+
field = field.substring(1)
|
|
43
|
+
projection[field] = -1;
|
|
44
|
+
} else {
|
|
45
|
+
projection[field] = 1;
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|