c2-mongoose 2.1.306 → 2.1.308
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/SearcherFlow.d.ts +38 -1
- package/dist/flow/SearcherFlow.js +26 -18
- package/package.json +1 -1
- package/src/flow/SearcherFlow.ts +27 -18
|
@@ -20,7 +20,6 @@ declare class SearcherFlow<D> {
|
|
|
20
20
|
orderBy: string;
|
|
21
21
|
groupBy: string[];
|
|
22
22
|
sumFields: string[];
|
|
23
|
-
groupFields: string[];
|
|
24
23
|
page: number;
|
|
25
24
|
limit: number;
|
|
26
25
|
pageable: boolean;
|
|
@@ -39,5 +38,43 @@ declare class SearcherFlow<D> {
|
|
|
39
38
|
buildOrdenation(): any;
|
|
40
39
|
buildRegex(searchText: string): RegExp;
|
|
41
40
|
buildGrouping(fieldsToGroup: string[], sumFields: string[], countFields: string[]): void;
|
|
41
|
+
buildPagination(): {
|
|
42
|
+
$addFields: {
|
|
43
|
+
page: number;
|
|
44
|
+
limit: number;
|
|
45
|
+
total: string;
|
|
46
|
+
totalPages: {
|
|
47
|
+
$cond: {
|
|
48
|
+
if: {
|
|
49
|
+
$eq: (string | number)[];
|
|
50
|
+
};
|
|
51
|
+
then: number;
|
|
52
|
+
else: {
|
|
53
|
+
$ceil: {
|
|
54
|
+
$divide: (string | number)[];
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
startIndex: {
|
|
60
|
+
$subtract: (number | {
|
|
61
|
+
$multiply: number[];
|
|
62
|
+
})[];
|
|
63
|
+
};
|
|
64
|
+
endIndex: {
|
|
65
|
+
$cond: {
|
|
66
|
+
if: {
|
|
67
|
+
$gt: (string | {
|
|
68
|
+
$multiply: number[];
|
|
69
|
+
})[];
|
|
70
|
+
};
|
|
71
|
+
then: string;
|
|
72
|
+
else: {
|
|
73
|
+
$multiply: number[];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
42
79
|
}
|
|
43
80
|
export default SearcherFlow;
|
|
@@ -72,7 +72,6 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
72
72
|
this.orderBy = "_id";
|
|
73
73
|
this.groupBy = [];
|
|
74
74
|
this.sumFields = [];
|
|
75
|
-
this.groupFields = [];
|
|
76
75
|
this.page = 1;
|
|
77
76
|
this.limit = 50;
|
|
78
77
|
this.pageable = true;
|
|
@@ -114,24 +113,9 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
114
113
|
if ((0, Utils_1.isNotEmpty)(options.unions)) {
|
|
115
114
|
stagesPaging.push.apply(stagesPaging, options.unions);
|
|
116
115
|
}
|
|
117
|
-
if ((0, Utils_1.isEmpty)(options.paging)) {
|
|
116
|
+
if ((0, Utils_1.isEmpty)(options.paging) && this.pageable) {
|
|
118
117
|
stagesPaging.push({ $match: this.filters });
|
|
119
|
-
stagesPaging.push(
|
|
120
|
-
stagesPaging.push({
|
|
121
|
-
$addFields: {
|
|
122
|
-
page: this.pageable === true ? this.page : 1,
|
|
123
|
-
limit: this.pageable === true ? this.limit : '$total',
|
|
124
|
-
totalPages: this.pageable === true ? {
|
|
125
|
-
$cond: {
|
|
126
|
-
if: { $eq: ['$total', 0] },
|
|
127
|
-
then: 0,
|
|
128
|
-
else: { $ceil: { $divide: ['$total', this.limit] } }
|
|
129
|
-
}
|
|
130
|
-
} : 1,
|
|
131
|
-
startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
|
|
132
|
-
endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
|
|
133
|
-
}
|
|
134
|
-
});
|
|
118
|
+
stagesPaging.push(this.buildPagination());
|
|
135
119
|
}
|
|
136
120
|
else {
|
|
137
121
|
stagesPaging = __spreadArray(__spreadArray([], stagesPaging, true), options.paging, true);
|
|
@@ -467,6 +451,30 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
467
451
|
groupsClauses.push(groupClause);
|
|
468
452
|
});
|
|
469
453
|
};
|
|
454
|
+
SearcherFlow.prototype.buildPagination = function () {
|
|
455
|
+
return {
|
|
456
|
+
$addFields: {
|
|
457
|
+
page: this.page,
|
|
458
|
+
limit: this.limit,
|
|
459
|
+
total: "$total",
|
|
460
|
+
totalPages: {
|
|
461
|
+
$cond: {
|
|
462
|
+
if: { $eq: ['$total', 0] },
|
|
463
|
+
then: 0,
|
|
464
|
+
else: { $ceil: { $divide: ['$total', this.limit] } }
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
startIndex: { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] },
|
|
468
|
+
endIndex: {
|
|
469
|
+
$cond: {
|
|
470
|
+
if: { $gt: [{ $multiply: [this.page, this.limit] }, "$total"] },
|
|
471
|
+
then: "$total",
|
|
472
|
+
else: { $multiply: [this.page, this.limit] }
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
};
|
|
470
478
|
return SearcherFlow;
|
|
471
479
|
}());
|
|
472
480
|
exports.default = SearcherFlow;
|
package/package.json
CHANGED
package/src/flow/SearcherFlow.ts
CHANGED
|
@@ -29,7 +29,6 @@ class SearcherFlow<D> {
|
|
|
29
29
|
public orderBy: string = "_id"
|
|
30
30
|
public groupBy: string[] = []
|
|
31
31
|
public sumFields: string[] = []
|
|
32
|
-
public groupFields: string[] = []
|
|
33
32
|
public page: number = 1
|
|
34
33
|
public limit: number = 50
|
|
35
34
|
public pageable: boolean = true
|
|
@@ -78,24 +77,9 @@ class SearcherFlow<D> {
|
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
|
|
81
|
-
if (isEmpty(options.paging)) {
|
|
80
|
+
if (isEmpty(options.paging) && this.pageable) {
|
|
82
81
|
stagesPaging.push({ $match: this.filters })
|
|
83
|
-
stagesPaging.push(
|
|
84
|
-
stagesPaging.push({
|
|
85
|
-
$addFields: {
|
|
86
|
-
page: this.pageable === true ? this.page : 1,
|
|
87
|
-
limit: this.pageable === true ? this.limit : '$total',
|
|
88
|
-
totalPages: this.pageable === true ? {
|
|
89
|
-
$cond: {
|
|
90
|
-
if: { $eq: ['$total', 0] },
|
|
91
|
-
then: 0,
|
|
92
|
-
else: { $ceil: { $divide: ['$total', this.limit] } }
|
|
93
|
-
}
|
|
94
|
-
} : 1,
|
|
95
|
-
startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
|
|
96
|
-
endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
|
|
97
|
-
}
|
|
98
|
-
})
|
|
82
|
+
stagesPaging.push(this.buildPagination())
|
|
99
83
|
} else {
|
|
100
84
|
stagesPaging = [...stagesPaging, ...options.paging]
|
|
101
85
|
}
|
|
@@ -460,6 +444,31 @@ class SearcherFlow<D> {
|
|
|
460
444
|
groupsClauses.push(groupClause)
|
|
461
445
|
})
|
|
462
446
|
}
|
|
447
|
+
|
|
448
|
+
buildPagination() {
|
|
449
|
+
return {
|
|
450
|
+
$addFields: {
|
|
451
|
+
page: this.page,
|
|
452
|
+
limit: this.limit,
|
|
453
|
+
total: "$total",
|
|
454
|
+
totalPages: {
|
|
455
|
+
$cond: {
|
|
456
|
+
if: { $eq: ['$total', 0] },
|
|
457
|
+
then: 0,
|
|
458
|
+
else: { $ceil: { $divide: ['$total', this.limit] } }
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
startIndex: { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] },
|
|
462
|
+
endIndex: {
|
|
463
|
+
$cond: {
|
|
464
|
+
if: { $gt: [{ $multiply: [this.page, this.limit] }, "$total"] },
|
|
465
|
+
then: "$total",
|
|
466
|
+
else: { $multiply: [this.page, this.limit] }
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
463
472
|
}
|
|
464
473
|
|
|
465
474
|
export default SearcherFlow
|