c2-mongoose 2.1.112 → 2.1.113
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 +5 -2
- package/dist/flow/C2Flow.js +43 -3
- package/dist/flow/item/BuildLogFlowItem.d.ts +2 -1
- package/dist/flow/item/BuildLogFlowItem.js +2 -1
- package/dist/model/Logger.d.ts +4 -0
- package/dist/model/Logger.js +1 -0
- package/package.json +1 -1
- package/src/flow/C2Flow.ts +29 -13
- package/src/flow/item/BuildLogFlowItem.ts +3 -1
- package/src/model/Logger.ts +2 -0
package/dist/flow/C2Flow.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
1
|
+
import mongoose, { Types } from "mongoose";
|
|
2
2
|
import { Options } from "../types/Options";
|
|
3
|
+
import SearchFlow from "./SearchFlow";
|
|
3
4
|
declare class C2Flow<D> {
|
|
4
5
|
private repository;
|
|
5
6
|
constructor(repository: mongoose.Model<any>);
|
|
6
|
-
create(data: Partial<D>, options: Partial<Options>): Promise<
|
|
7
|
+
create(data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
8
|
+
updateById(id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
9
|
+
updateByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
|
|
7
10
|
}
|
|
8
11
|
export default C2Flow;
|
package/dist/flow/C2Flow.js
CHANGED
|
@@ -54,13 +54,53 @@ var C2Flow = /** @class */ (function () {
|
|
|
54
54
|
case 1:
|
|
55
55
|
dataAfter = _a.sent();
|
|
56
56
|
if (options.logger === false) {
|
|
57
|
-
return [2 /*return*/, dataAfter];
|
|
57
|
+
return [2 /*return*/, dataAfter[0]._doc];
|
|
58
58
|
}
|
|
59
|
-
log = BuildLogFlowItem_1.default.build(options, dataAfter, Logger_1.TypeOfOperation.CREATE);
|
|
59
|
+
log = BuildLogFlowItem_1.default.build(options, dataAfter[0]._doc, Logger_1.TypeOfOperation.CREATE, this.repository);
|
|
60
60
|
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
|
|
61
61
|
case 2:
|
|
62
62
|
_a.sent();
|
|
63
|
-
return [2 /*return*/, dataAfter];
|
|
63
|
+
return [2 /*return*/, dataAfter[0]._doc];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
C2Flow.prototype.updateById = function (id, data, options) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var dataAfter, log;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0: return [4 /*yield*/, this.repository.findByIdAndUpdate(id, data, { returnDocument: 'after', session: options.session })];
|
|
74
|
+
case 1:
|
|
75
|
+
dataAfter = _a.sent();
|
|
76
|
+
if (options.logger === false) {
|
|
77
|
+
return [2 /*return*/, dataAfter._doc];
|
|
78
|
+
}
|
|
79
|
+
log = BuildLogFlowItem_1.default.build(options, dataAfter._doc, Logger_1.TypeOfOperation.UPDATE, this.repository);
|
|
80
|
+
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
|
|
81
|
+
case 2:
|
|
82
|
+
_a.sent();
|
|
83
|
+
return [2 /*return*/, dataAfter._doc];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
C2Flow.prototype.updateByModel = function (searcher, data, options) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
var dataAfter, log;
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0: return [4 /*yield*/, this.repository.findOneAndUpdate(searcher.filters, data, { session: options.session })];
|
|
94
|
+
case 1:
|
|
95
|
+
dataAfter = _a.sent();
|
|
96
|
+
if (options.logger === false) {
|
|
97
|
+
return [2 /*return*/, dataAfter._doc];
|
|
98
|
+
}
|
|
99
|
+
log = BuildLogFlowItem_1.default.build(options, dataAfter._doc, Logger_1.TypeOfOperation.UPDATE, this.repository);
|
|
100
|
+
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
|
|
101
|
+
case 2:
|
|
102
|
+
_a.sent();
|
|
103
|
+
return [2 /*return*/, dataAfter._doc];
|
|
64
104
|
}
|
|
65
105
|
});
|
|
66
106
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ILogger, TypeOfOperation } from "../../model/Logger";
|
|
2
2
|
import { Options } from "../../types/Options";
|
|
3
|
+
import mongoose from "mongoose";
|
|
3
4
|
declare class BuildLogFlowItem {
|
|
4
|
-
build(options: Partial<Options>, dataAfter: any[], operation: TypeOfOperation): Partial<ILogger>;
|
|
5
|
+
build(options: Partial<Options>, dataAfter: any[], operation: TypeOfOperation, repository: mongoose.Model<any>): Partial<ILogger>;
|
|
5
6
|
}
|
|
6
7
|
declare const _default: BuildLogFlowItem;
|
|
7
8
|
export default _default;
|
|
@@ -7,12 +7,13 @@ var express_http_context_1 = __importDefault(require("express-http-context"));
|
|
|
7
7
|
var BuildLogFlowItem = /** @class */ (function () {
|
|
8
8
|
function BuildLogFlowItem() {
|
|
9
9
|
}
|
|
10
|
-
BuildLogFlowItem.prototype.build = function (options, dataAfter, operation) {
|
|
10
|
+
BuildLogFlowItem.prototype.build = function (options, dataAfter, operation, repository) {
|
|
11
11
|
var _a;
|
|
12
12
|
return {
|
|
13
13
|
user: (_a = options.owner) !== null && _a !== void 0 ? _a : express_http_context_1.default.get("user")._id,
|
|
14
14
|
owner: options.owner,
|
|
15
15
|
data: dataAfter,
|
|
16
|
+
collection: repository.collection.name,
|
|
16
17
|
operation: operation
|
|
17
18
|
};
|
|
18
19
|
};
|
package/dist/model/Logger.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare enum TypeOfOperation {
|
|
|
9
9
|
interface ILogger {
|
|
10
10
|
owner: Types.ObjectId;
|
|
11
11
|
user: Types.ObjectId;
|
|
12
|
+
collection: string;
|
|
12
13
|
createdAtDateTime: moment.Moment;
|
|
13
14
|
operation: TypeOfOperation;
|
|
14
15
|
data: any;
|
|
@@ -18,6 +19,7 @@ declare const LoggerModel: mongoose.Schema<any, mongoose.Model<any, any, any, an
|
|
|
18
19
|
createdAt: string;
|
|
19
20
|
};
|
|
20
21
|
}>, {
|
|
22
|
+
collection: string;
|
|
21
23
|
owner: {
|
|
22
24
|
prototype?: Types.ObjectId | undefined;
|
|
23
25
|
cacheHexString?: unknown;
|
|
@@ -37,6 +39,7 @@ declare const LoggerModel: mongoose.Schema<any, mongoose.Model<any, any, any, an
|
|
|
37
39
|
operation: string;
|
|
38
40
|
data?: any;
|
|
39
41
|
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
42
|
+
collection: string;
|
|
40
43
|
owner: {
|
|
41
44
|
prototype?: Types.ObjectId | undefined;
|
|
42
45
|
cacheHexString?: unknown;
|
|
@@ -56,6 +59,7 @@ declare const LoggerModel: mongoose.Schema<any, mongoose.Model<any, any, any, an
|
|
|
56
59
|
operation: string;
|
|
57
60
|
data?: any;
|
|
58
61
|
}>> & Omit<mongoose.FlatRecord<{
|
|
62
|
+
collection: string;
|
|
59
63
|
owner: {
|
|
60
64
|
prototype?: Types.ObjectId | undefined;
|
|
61
65
|
cacheHexString?: unknown;
|
package/dist/model/Logger.js
CHANGED
|
@@ -55,6 +55,7 @@ exports.TypeOfOperation = TypeOfOperation;
|
|
|
55
55
|
var LoggerModel = new mongoose_1.Schema({
|
|
56
56
|
owner: { type: mongoose_1.Types.ObjectId, required: true, immutable: true },
|
|
57
57
|
user: { type: mongoose_1.Types.ObjectId, required: true, immutable: true },
|
|
58
|
+
collection: { type: String, required: true, immutable: true },
|
|
58
59
|
operation: { type: String, enum: TypeOfOperation, required: true, immutable: true },
|
|
59
60
|
data: { type: mongoose_1.default.Schema.Types.Mixed, immutable: true }
|
|
60
61
|
}, {
|
package/package.json
CHANGED
package/src/flow/C2Flow.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
import mongoose from "mongoose"
|
|
2
|
+
import mongoose, { Types } from "mongoose"
|
|
3
3
|
import { ILogger, TypeOfOperation } from "../model/Logger"
|
|
4
4
|
import { Options } from "../types/Options"
|
|
5
5
|
import BuildLogFlowItem from "./item/BuildLogFlowItem"
|
|
6
|
+
import SearchFlow from "./SearchFlow"
|
|
6
7
|
|
|
7
8
|
class C2Flow<D> {
|
|
8
9
|
|
|
@@ -12,29 +13,44 @@ class C2Flow<D> {
|
|
|
12
13
|
this.repository = repository
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
async create(data: Partial<D>, options: Partial<Options>): Promise<Partial<D>> {
|
|
16
17
|
let dataAfter = await this.repository.create([data], { session: options.session })
|
|
17
18
|
|
|
18
19
|
if (options.logger === false) {
|
|
19
|
-
return dataAfter
|
|
20
|
+
return dataAfter[0]._doc
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
let log: Partial<ILogger> = BuildLogFlowItem.build(options, dataAfter, TypeOfOperation.CREATE)
|
|
23
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, dataAfter[0]._doc, TypeOfOperation.CREATE, this.repository)
|
|
23
24
|
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
24
25
|
|
|
25
|
-
return dataAfter
|
|
26
|
+
return dataAfter[0]._doc
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
async updateById(id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>> {
|
|
30
|
+
let dataAfter = await this.repository.findByIdAndUpdate(id, data, { returnDocument: 'after', session: options.session })
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
if (options.logger === false) {
|
|
33
|
+
return dataAfter._doc
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, dataAfter._doc, TypeOfOperation.UPDATE, this.repository)
|
|
37
|
+
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
38
|
+
|
|
39
|
+
return dataAfter._doc
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async updateByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>> {
|
|
43
|
+
let dataAfter = await this.repository.findOneAndUpdate(searcher.filters, data, { session: options.session })
|
|
33
44
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
if (options.logger === false) {
|
|
46
|
+
return dataAfter._doc
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let log: Partial<ILogger> = BuildLogFlowItem.build(options, dataAfter._doc, TypeOfOperation.UPDATE, this.repository)
|
|
50
|
+
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
51
|
+
|
|
52
|
+
return dataAfter._doc
|
|
53
|
+
}
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
export default C2Flow
|
|
@@ -1,13 +1,15 @@
|
|
|
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
5
|
|
|
5
6
|
class BuildLogFlowItem {
|
|
6
|
-
build(options: Partial<Options>, dataAfter: any[], operation: TypeOfOperation): Partial<ILogger> {
|
|
7
|
+
build(options: Partial<Options>, dataAfter: any[], operation: TypeOfOperation, repository: mongoose.Model<any>): Partial<ILogger> {
|
|
7
8
|
return {
|
|
8
9
|
user: options.owner ?? httpContext.get("user")._id,
|
|
9
10
|
owner: options.owner,
|
|
10
11
|
data: dataAfter,
|
|
12
|
+
collection: repository.collection.name,
|
|
11
13
|
operation
|
|
12
14
|
}
|
|
13
15
|
}
|
package/src/model/Logger.ts
CHANGED
|
@@ -12,6 +12,7 @@ enum TypeOfOperation {
|
|
|
12
12
|
interface ILogger {
|
|
13
13
|
owner: Types.ObjectId
|
|
14
14
|
user: Types.ObjectId
|
|
15
|
+
collection: string
|
|
15
16
|
createdAtDateTime: moment.Moment
|
|
16
17
|
operation: TypeOfOperation
|
|
17
18
|
data: any
|
|
@@ -20,6 +21,7 @@ interface ILogger {
|
|
|
20
21
|
const LoggerModel = new Schema({
|
|
21
22
|
owner: { type: Types.ObjectId, required: true, immutable: true },
|
|
22
23
|
user: { type: Types.ObjectId, required: true, immutable: true },
|
|
24
|
+
collection: { type: String, required: true, immutable: true },
|
|
23
25
|
operation: { type: String, enum: TypeOfOperation, required: true, immutable: true },
|
|
24
26
|
data: { type: mongoose.Schema.Types.Mixed, immutable: true }
|
|
25
27
|
}, {
|