c2-mongoose 2.1.359 → 2.1.361
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.js +2 -2
- package/dist/flow/searcher/v3/SearcherV3Flow.d.ts +2 -1
- package/dist/flow/searcher/v3/SearcherV3Flow.js +4 -1
- package/dist/flow/searcher/v3/item/OneToManyFlowItem.d.ts +9 -0
- package/dist/flow/searcher/v3/item/OneToManyFlowItem.js +34 -0
- package/package.json +1 -1
- package/src/flow/C2Flow.ts +2 -2
- package/src/flow/searcher/v3/SearcherV3Flow.ts +4 -2
- package/src/flow/searcher/v3/item/OneToManyFlowItem.ts +30 -0
package/dist/flow/C2Flow.js
CHANGED
|
@@ -82,14 +82,14 @@ var C2Flow = /** @class */ (function () {
|
|
|
82
82
|
var dataAfter, log;
|
|
83
83
|
return __generator(this, function (_a) {
|
|
84
84
|
switch (_a.label) {
|
|
85
|
-
case 0: return [4 /*yield*/, this.repository.create(data, { session: options.session })];
|
|
85
|
+
case 0: return [4 /*yield*/, this.repository.create(data, { session: options.session, ordered: true })];
|
|
86
86
|
case 1:
|
|
87
87
|
dataAfter = _a.sent();
|
|
88
88
|
if (options.logger === false || (0, Utils_1.isEmpty)(dataAfter)) {
|
|
89
89
|
return [2 /*return*/, dataAfter];
|
|
90
90
|
}
|
|
91
91
|
log = BuildLogFlowItem_1.default.build(options, dataAfter[0]._doc, Logger_1.TypeOfOperation.CREATE, this.repository);
|
|
92
|
-
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
|
|
92
|
+
return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session, ordered: true })];
|
|
93
93
|
case 2:
|
|
94
94
|
_a.sent();
|
|
95
95
|
return [2 /*return*/, dataAfter];
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
+
import { IForeingData } from "./item/OneToManyFlowItem";
|
|
2
3
|
export interface IParams {
|
|
3
4
|
[key: string]: any;
|
|
4
5
|
mainFilter: any;
|
|
5
6
|
}
|
|
6
7
|
declare class SearcherV3Flow {
|
|
7
|
-
exec(params: IParams, model: mongoose.Model<any
|
|
8
|
+
exec(params: IParams, model: mongoose.Model<any>, oneToMany?: IForeingData[]): Promise<any>;
|
|
8
9
|
}
|
|
9
10
|
declare const _default: SearcherV3Flow;
|
|
10
11
|
export default _default;
|
|
@@ -54,11 +54,13 @@ var PopulateFlowItem_1 = __importDefault(require("./item/PopulateFlowItem"));
|
|
|
54
54
|
var SortFlowItem_1 = __importDefault(require("./item/SortFlowItem"));
|
|
55
55
|
var ProjectFlowItem_1 = __importDefault(require("./item/ProjectFlowItem"));
|
|
56
56
|
var BuildPaginationDataFlowItem_1 = __importDefault(require("./item/BuildPaginationDataFlowItem"));
|
|
57
|
+
var OneToManyFlowItem_1 = __importDefault(require("./item/OneToManyFlowItem"));
|
|
57
58
|
var SearcherV3Flow = /** @class */ (function () {
|
|
58
59
|
function SearcherV3Flow() {
|
|
59
60
|
}
|
|
60
|
-
SearcherV3Flow.prototype.exec = function (params, model) {
|
|
61
|
+
SearcherV3Flow.prototype.exec = function (params, model, oneToMany) {
|
|
61
62
|
var _a, _b, _c;
|
|
63
|
+
if (oneToMany === void 0) { oneToMany = []; }
|
|
62
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
63
65
|
var facet, pipelineFacetPaging, pipelineFacetItems, mainFilters, result, ret;
|
|
64
66
|
return __generator(this, function (_d) {
|
|
@@ -71,6 +73,7 @@ var SearcherV3Flow = /** @class */ (function () {
|
|
|
71
73
|
pipelineFacetItems = [];
|
|
72
74
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), GroupFlowItem_1.default.execute(params.groupBy, params.sumFields, params.groupDetailed, model), true);
|
|
73
75
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), PopulateFlowItem_1.default.execute(params.populate, model), true);
|
|
76
|
+
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), OneToManyFlowItem_1.default.execute(oneToMany), true);
|
|
74
77
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), MatchFlowItem_1.default.execute(params, model), true);
|
|
75
78
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), SortFlowItem_1.default.execute(params.orderBy, params.orderSense), true);
|
|
76
79
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), ProjectFlowItem_1.default.execute(params.select), true);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var OneToManyFlowItem = /** @class */ (function () {
|
|
13
|
+
function OneToManyFlowItem() {
|
|
14
|
+
}
|
|
15
|
+
OneToManyFlowItem.prototype.execute = function (foreings) {
|
|
16
|
+
var collection = [];
|
|
17
|
+
foreings === null || foreings === void 0 ? void 0 : foreings.forEach(function (foreing) {
|
|
18
|
+
var populateClauseLookup = [
|
|
19
|
+
{
|
|
20
|
+
$lookup: {
|
|
21
|
+
from: foreing.collectionChild,
|
|
22
|
+
localField: "_id",
|
|
23
|
+
foreignField: foreing.parentFieldOnChild,
|
|
24
|
+
as: foreing.collectionChild
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
collection = __spreadArray(__spreadArray([], collection, true), populateClauseLookup, true);
|
|
29
|
+
});
|
|
30
|
+
return collection;
|
|
31
|
+
};
|
|
32
|
+
return OneToManyFlowItem;
|
|
33
|
+
}());
|
|
34
|
+
exports.default = new OneToManyFlowItem;
|
package/package.json
CHANGED
package/src/flow/C2Flow.ts
CHANGED
|
@@ -28,14 +28,14 @@ class C2Flow<D> {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
async createMany(data: Partial<D>[], options: Partial<Options>): Promise<Partial<D>[]> {
|
|
31
|
-
let dataAfter = await this.repository.create(data, { session: options.session })
|
|
31
|
+
let dataAfter = await this.repository.create(data, { session: options.session, ordered: true })
|
|
32
32
|
|
|
33
33
|
if (options.logger === false || isEmpty(dataAfter)) {
|
|
34
34
|
return dataAfter
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
let log: Partial<ILogger> = BuildLogFlowItem.build(options, dataAfter[0]._doc, TypeOfOperation.CREATE, this.repository)
|
|
38
|
-
await (global as any).LoggerRepository.create([log], { session: options.session })
|
|
38
|
+
await (global as any).LoggerRepository.create([log], { session: options.session, ordered: true })
|
|
39
39
|
|
|
40
40
|
return dataAfter
|
|
41
41
|
}
|
|
@@ -5,6 +5,7 @@ import PopulateFlowItem from "./item/PopulateFlowItem"
|
|
|
5
5
|
import SortFlowItem from "./item/SortFlowItem"
|
|
6
6
|
import ProjectFlowItem from "./item/ProjectFlowItem"
|
|
7
7
|
import BuildPaginationDataFlowItem from "./item/BuildPaginationDataFlowItem"
|
|
8
|
+
import OneToManyFlowItem, { IForeingData } from "./item/OneToManyFlowItem"
|
|
8
9
|
|
|
9
10
|
export interface IParams {
|
|
10
11
|
[key: string]: any
|
|
@@ -13,7 +14,7 @@ export interface IParams {
|
|
|
13
14
|
|
|
14
15
|
class SearcherV3Flow {
|
|
15
16
|
|
|
16
|
-
async exec(params: IParams, model: mongoose.Model<any
|
|
17
|
+
async exec(params: IParams, model: mongoose.Model<any>, oneToMany: IForeingData[] = []) {
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
params.page = Number(params.page ?? 1)
|
|
@@ -23,7 +24,8 @@ class SearcherV3Flow {
|
|
|
23
24
|
let pipelineFacetPaging: any[] = []
|
|
24
25
|
let pipelineFacetItems: any[] = []
|
|
25
26
|
pipelineFacetItems = [...pipelineFacetItems, ...GroupFlowItem.execute(params.groupBy, params.sumFields, params.groupDetailed, model)]
|
|
26
|
-
pipelineFacetItems = [...pipelineFacetItems, ...PopulateFlowItem.execute(params.populate, model)
|
|
27
|
+
pipelineFacetItems = [...pipelineFacetItems, ...PopulateFlowItem.execute(params.populate, model)]
|
|
28
|
+
pipelineFacetItems = [...pipelineFacetItems, ...OneToManyFlowItem.execute(oneToMany)]
|
|
27
29
|
pipelineFacetItems = [...pipelineFacetItems, ...MatchFlowItem.execute(params, model)]
|
|
28
30
|
pipelineFacetItems = [...pipelineFacetItems, ...SortFlowItem.execute(params.orderBy, params.orderSense)]
|
|
29
31
|
pipelineFacetItems = [...pipelineFacetItems, ...ProjectFlowItem.execute(params.select)]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
export interface IForeingData {
|
|
4
|
+
collectionChild: string;
|
|
5
|
+
parentFieldOnChild: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class OneToManyFlowItem {
|
|
9
|
+
execute(foreings: IForeingData[]): any[] {
|
|
10
|
+
let collection: any[] = []
|
|
11
|
+
foreings?.forEach((foreing: IForeingData) => {
|
|
12
|
+
const populateClauseLookup: any[] = [
|
|
13
|
+
{
|
|
14
|
+
$lookup: {
|
|
15
|
+
from: foreing.collectionChild, // The collection where user data is stored
|
|
16
|
+
localField: "_id",
|
|
17
|
+
foreignField: foreing.parentFieldOnChild,
|
|
18
|
+
as: foreing.collectionChild
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
collection = [...collection, ...populateClauseLookup]
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
return collection
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default new OneToManyFlowItem
|