c2-mongoose 2.1.116 → 2.1.118
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
CHANGED
|
@@ -7,5 +7,7 @@ declare class C2Flow<D> {
|
|
|
7
7
|
create(data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
8
8
|
updateById(_id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
9
9
|
updateByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
10
|
+
deleteById(_id: Types.ObjectId, options: Partial<Options>): Promise<void>;
|
|
11
|
+
deleteByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<void>;
|
|
10
12
|
}
|
|
11
13
|
export default C2Flow;
|
package/dist/flow/C2Flow.js
CHANGED
|
@@ -116,6 +116,46 @@ var C2Flow = /** @class */ (function () {
|
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
};
|
|
119
|
+
C2Flow.prototype.deleteById = function (_id, options) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
+
var dataAfter, log;
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
switch (_a.label) {
|
|
124
|
+
case 0: return [4 /*yield*/, this.repository.findByIdAndRemove(_id, { session: options.session })];
|
|
125
|
+
case 1:
|
|
126
|
+
dataAfter = _a.sent();
|
|
127
|
+
if (options.logger === false) {
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
log = BuildLogFlowItem_1.default.build(options, __assign({ _id: _id }, dataAfter._doc), Logger_1.TypeOfOperation.DELETE, this.repository);
|
|
131
|
+
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
|
|
132
|
+
case 2:
|
|
133
|
+
_a.sent();
|
|
134
|
+
return [2 /*return*/];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
C2Flow.prototype.deleteByModel = function (searcher, data, options) {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
+
var dataAfter, log;
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
switch (_a.label) {
|
|
144
|
+
case 0: return [4 /*yield*/, this.repository.deleteMany(searcher.filters).session(options.session)];
|
|
145
|
+
case 1:
|
|
146
|
+
dataAfter = _a.sent();
|
|
147
|
+
if (options.logger === false) {
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
log = BuildLogFlowItem_1.default.build(options, __assign(__assign({}, searcher.filters), dataAfter), Logger_1.TypeOfOperation.DELETE, this.repository);
|
|
151
|
+
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
|
|
152
|
+
case 2:
|
|
153
|
+
_a.sent();
|
|
154
|
+
return [2 /*return*/];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
119
159
|
return C2Flow;
|
|
120
160
|
}());
|
|
121
161
|
exports.default = C2Flow;
|
|
@@ -4,14 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var express_http_context_1 = __importDefault(require("express-http-context"));
|
|
7
|
+
var mongoose_1 = require("mongoose");
|
|
7
8
|
var BuildLogFlowItem = /** @class */ (function () {
|
|
8
9
|
function BuildLogFlowItem() {
|
|
9
10
|
}
|
|
10
11
|
BuildLogFlowItem.prototype.build = function (options, dataAfter, operation, repository) {
|
|
11
12
|
var _a;
|
|
12
13
|
return {
|
|
13
|
-
user: (_a = options.user) !== null && _a !== void 0 ? _a : express_http_context_1.default.get("user")._id,
|
|
14
|
-
owner: options.owner,
|
|
14
|
+
user: new mongoose_1.Types.ObjectId((_a = options.user) !== null && _a !== void 0 ? _a : express_http_context_1.default.get("user")._id),
|
|
15
|
+
owner: new mongoose_1.Types.ObjectId(options.owner),
|
|
15
16
|
data: dataAfter,
|
|
16
17
|
collectionName: repository.collection.name,
|
|
17
18
|
operation: operation
|
package/package.json
CHANGED
package/src/flow/C2Flow.ts
CHANGED
|
@@ -51,6 +51,31 @@ class C2Flow<D> {
|
|
|
51
51
|
|
|
52
52
|
return dataAfter._doc
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
public async deleteById(_id: Types.ObjectId, options: Partial<Options>) {
|
|
57
|
+
|
|
58
|
+
let dataAfter = await this.repository.findByIdAndRemove(_id, { session: options.session })
|
|
59
|
+
|
|
60
|
+
if (options.logger === false) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, { _id, ...dataAfter._doc }, TypeOfOperation.DELETE, this.repository)
|
|
65
|
+
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public async deleteByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>) {
|
|
69
|
+
|
|
70
|
+
let dataAfter = await this.repository.deleteMany(searcher.filters).session(options.session!)
|
|
71
|
+
|
|
72
|
+
if (options.logger === false) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, { ...searcher.filters, ...dataAfter }, TypeOfOperation.DELETE, this.repository)
|
|
77
|
+
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
78
|
+
}
|
|
54
79
|
}
|
|
55
80
|
|
|
56
81
|
export default C2Flow
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import httpContext from "express-http-context"
|
|
2
2
|
import { ILogger, TypeOfOperation } from "../../model/Logger"
|
|
3
3
|
import { Options } from "../../types/Options"
|
|
4
|
-
import mongoose from "mongoose"
|
|
4
|
+
import mongoose, { Types } from "mongoose"
|
|
5
5
|
|
|
6
6
|
class BuildLogFlowItem {
|
|
7
7
|
build(options: Partial<Options>, dataAfter: any, operation: TypeOfOperation, repository: mongoose.Model<any>): Partial<ILogger> {
|
|
8
8
|
return {
|
|
9
|
-
user: options.user ?? httpContext.get("user")._id,
|
|
10
|
-
owner: options.owner,
|
|
9
|
+
user: new Types.ObjectId(options.user ?? httpContext.get("user")._id),
|
|
10
|
+
owner: new Types.ObjectId(options.owner),
|
|
11
11
|
data: dataAfter,
|
|
12
12
|
collectionName: repository.collection.name,
|
|
13
13
|
operation
|