c2-mongoose 2.1.307 → 2.1.309
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 +1 -0
- package/dist/flow/SearcherFlow.js +29 -17
- package/package.json +1 -1
- package/src/flow/SearcherFlow.ts +30 -17
|
@@ -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.buildPaginationData());
|
|
134
119
|
}
|
|
135
120
|
else {
|
|
136
121
|
stagesPaging = __spreadArray(__spreadArray([], stagesPaging, true), options.paging, true);
|
|
@@ -466,6 +451,33 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
466
451
|
groupsClauses.push(groupClause);
|
|
467
452
|
});
|
|
468
453
|
};
|
|
454
|
+
SearcherFlow.prototype.buildPaginationData = function () {
|
|
455
|
+
return [
|
|
456
|
+
{ $count: "total" },
|
|
457
|
+
{
|
|
458
|
+
$addFields: {
|
|
459
|
+
page: this.page,
|
|
460
|
+
limit: this.limit,
|
|
461
|
+
total: "$total",
|
|
462
|
+
totalPages: {
|
|
463
|
+
$cond: {
|
|
464
|
+
if: { $eq: ['$total', 0] },
|
|
465
|
+
then: 0,
|
|
466
|
+
else: { $ceil: { $divide: ['$total', this.limit] } }
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
startIndex: { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] },
|
|
470
|
+
endIndex: {
|
|
471
|
+
$cond: {
|
|
472
|
+
if: { $gt: [{ $multiply: [this.page, this.limit] }, "$total"] },
|
|
473
|
+
then: "$total",
|
|
474
|
+
else: { $multiply: [this.page, this.limit] }
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
];
|
|
480
|
+
};
|
|
469
481
|
return SearcherFlow;
|
|
470
482
|
}());
|
|
471
483
|
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.buildPaginationData())
|
|
98
83
|
} else {
|
|
99
84
|
stagesPaging = [...stagesPaging, ...options.paging]
|
|
100
85
|
}
|
|
@@ -459,6 +444,34 @@ class SearcherFlow<D> {
|
|
|
459
444
|
groupsClauses.push(groupClause)
|
|
460
445
|
})
|
|
461
446
|
}
|
|
447
|
+
|
|
448
|
+
buildPaginationData(): any[] {
|
|
449
|
+
return [
|
|
450
|
+
{ $count: "total" },
|
|
451
|
+
{
|
|
452
|
+
$addFields: {
|
|
453
|
+
page: this.page,
|
|
454
|
+
limit: this.limit,
|
|
455
|
+
total: "$total",
|
|
456
|
+
totalPages: {
|
|
457
|
+
$cond: {
|
|
458
|
+
if: { $eq: ['$total', 0] },
|
|
459
|
+
then: 0,
|
|
460
|
+
else: { $ceil: { $divide: ['$total', this.limit] } }
|
|
461
|
+
}
|
|
462
|
+
},
|
|
463
|
+
startIndex: { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] },
|
|
464
|
+
endIndex: {
|
|
465
|
+
$cond: {
|
|
466
|
+
if: { $gt: [{ $multiply: [this.page, this.limit] }, "$total"] },
|
|
467
|
+
then: "$total",
|
|
468
|
+
else: { $multiply: [this.page, this.limit] }
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
]
|
|
474
|
+
}
|
|
462
475
|
}
|
|
463
476
|
|
|
464
477
|
export default SearcherFlow
|