c2-mongoose 2.1.307 → 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 -0
- package/dist/flow/SearcherFlow.js +26 -17
- package/package.json +1 -1
- package/src/flow/SearcherFlow.ts +27 -17
|
@@ -38,5 +38,43 @@ declare class SearcherFlow<D> {
|
|
|
38
38
|
buildOrdenation(): any;
|
|
39
39
|
buildRegex(searchText: string): RegExp;
|
|
40
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
|
+
};
|
|
41
79
|
}
|
|
42
80
|
export default SearcherFlow;
|
|
@@ -113,24 +113,9 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
113
113
|
if ((0, Utils_1.isNotEmpty)(options.unions)) {
|
|
114
114
|
stagesPaging.push.apply(stagesPaging, options.unions);
|
|
115
115
|
}
|
|
116
|
-
if ((0, Utils_1.isEmpty)(options.paging)) {
|
|
116
|
+
if ((0, Utils_1.isEmpty)(options.paging) && this.pageable) {
|
|
117
117
|
stagesPaging.push({ $match: this.filters });
|
|
118
|
-
stagesPaging.push(
|
|
119
|
-
stagesPaging.push({
|
|
120
|
-
$addFields: {
|
|
121
|
-
page: this.pageable === true ? this.page : 1,
|
|
122
|
-
limit: this.pageable === true ? this.limit : '$total',
|
|
123
|
-
totalPages: this.pageable === true ? {
|
|
124
|
-
$cond: {
|
|
125
|
-
if: { $eq: ['$total', 0] },
|
|
126
|
-
then: 0,
|
|
127
|
-
else: { $ceil: { $divide: ['$total', this.limit] } }
|
|
128
|
-
}
|
|
129
|
-
} : 1,
|
|
130
|
-
startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
|
|
131
|
-
endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
|
|
132
|
-
}
|
|
133
|
-
});
|
|
118
|
+
stagesPaging.push(this.buildPagination());
|
|
134
119
|
}
|
|
135
120
|
else {
|
|
136
121
|
stagesPaging = __spreadArray(__spreadArray([], stagesPaging, true), options.paging, true);
|
|
@@ -466,6 +451,30 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
466
451
|
groupsClauses.push(groupClause);
|
|
467
452
|
});
|
|
468
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
|
+
};
|
|
469
478
|
return SearcherFlow;
|
|
470
479
|
}());
|
|
471
480
|
exports.default = SearcherFlow;
|
package/package.json
CHANGED
package/src/flow/SearcherFlow.ts
CHANGED
|
@@ -77,24 +77,9 @@ class SearcherFlow<D> {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
|
|
80
|
-
if (isEmpty(options.paging)) {
|
|
80
|
+
if (isEmpty(options.paging) && this.pageable) {
|
|
81
81
|
stagesPaging.push({ $match: this.filters })
|
|
82
|
-
stagesPaging.push(
|
|
83
|
-
stagesPaging.push({
|
|
84
|
-
$addFields: {
|
|
85
|
-
page: this.pageable === true ? this.page : 1,
|
|
86
|
-
limit: this.pageable === true ? this.limit : '$total',
|
|
87
|
-
totalPages: this.pageable === true ? {
|
|
88
|
-
$cond: {
|
|
89
|
-
if: { $eq: ['$total', 0] },
|
|
90
|
-
then: 0,
|
|
91
|
-
else: { $ceil: { $divide: ['$total', this.limit] } }
|
|
92
|
-
}
|
|
93
|
-
} : 1,
|
|
94
|
-
startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
|
|
95
|
-
endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
|
|
96
|
-
}
|
|
97
|
-
})
|
|
82
|
+
stagesPaging.push(this.buildPagination())
|
|
98
83
|
} else {
|
|
99
84
|
stagesPaging = [...stagesPaging, ...options.paging]
|
|
100
85
|
}
|
|
@@ -459,6 +444,31 @@ class SearcherFlow<D> {
|
|
|
459
444
|
groupsClauses.push(groupClause)
|
|
460
445
|
})
|
|
461
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
|
+
}
|
|
462
472
|
}
|
|
463
473
|
|
|
464
474
|
export default SearcherFlow
|