c2-mongoose 2.1.203 → 2.1.204

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.
@@ -256,7 +256,21 @@ var SearchFlow = /** @class */ (function () {
256
256
  }
257
257
  stagesPaging.push({ $match: this.filters });
258
258
  stagesPaging.push({ $count: "total" });
259
- stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } });
259
+ stagesPaging.push({
260
+ $addFields: {
261
+ page: this.page || 1,
262
+ limit: this.limit,
263
+ totalPages: {
264
+ $cond: {
265
+ if: { $eq: ['$total', 0] },
266
+ then: 0,
267
+ else: { $ceil: { $divide: ['$total', this.limit] } }
268
+ }
269
+ },
270
+ startIndex: { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit] },
271
+ endIndex: { $multiply: [this.page, this.limit] }
272
+ }
273
+ });
260
274
  stagesMetadata = [];
261
275
  if ((0, Utils_1.isNotEmpty)(options.metadata)) {
262
276
  stagesMetadata.push.apply(stagesMetadata, options.metadata);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.203",
3
+ "version": "2.1.204",
4
4
  "description": "Lib to make any search in database mongoose and use as basic crud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -243,7 +243,22 @@ abstract class SearchFlow {
243
243
  }
244
244
  stagesPaging.push({ $match: this.filters })
245
245
  stagesPaging.push({ $count: "total" })
246
- stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } })
246
+ stagesPaging.push(
247
+ {
248
+ $addFields: {
249
+ page: this.page || 1,
250
+ limit: this.limit,
251
+ totalPages: {
252
+ $cond: {
253
+ if: { $eq: ['$total', 0] },
254
+ then: 0,
255
+ else: { $ceil: { $divide: ['$total', this.limit] } }
256
+ }
257
+ },
258
+ startIndex: { $subtract: [ { $multiply: [this.page, this.limit] }, this.limit ] },
259
+ endIndex: { $multiply: [this.page, this.limit] }
260
+ }
261
+ })
247
262
 
248
263
  let stagesMetadata: any[] = []
249
264
  if (isNotEmpty(options.metadata)) {