c2-mongoose 2.1.308 → 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.
@@ -38,43 +38,6 @@ 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
+ buildPaginationData(): any[];
79
42
  }
80
43
  export default SearcherFlow;
@@ -115,7 +115,7 @@ var SearcherFlow = /** @class */ (function () {
115
115
  }
116
116
  if ((0, Utils_1.isEmpty)(options.paging) && this.pageable) {
117
117
  stagesPaging.push({ $match: this.filters });
118
- stagesPaging.push(this.buildPagination());
118
+ stagesPaging.push(this.buildPaginationData());
119
119
  }
120
120
  else {
121
121
  stagesPaging = __spreadArray(__spreadArray([], stagesPaging, true), options.paging, true);
@@ -451,29 +451,32 @@ var SearcherFlow = /** @class */ (function () {
451
451
  groupsClauses.push(groupClause);
452
452
  });
453
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] }
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
+ }
473
476
  }
474
477
  }
475
478
  }
476
- };
479
+ ];
477
480
  };
478
481
  return SearcherFlow;
479
482
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.308",
3
+ "version": "2.1.309",
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",
@@ -79,7 +79,7 @@ class SearcherFlow<D> {
79
79
 
80
80
  if (isEmpty(options.paging) && this.pageable) {
81
81
  stagesPaging.push({ $match: this.filters })
82
- stagesPaging.push(this.buildPagination())
82
+ stagesPaging.push(this.buildPaginationData())
83
83
  } else {
84
84
  stagesPaging = [...stagesPaging, ...options.paging]
85
85
  }
@@ -445,29 +445,32 @@ class SearcherFlow<D> {
445
445
  })
446
446
  }
447
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] }
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
+ }
467
470
  }
468
471
  }
469
472
  }
470
- }
473
+ ]
471
474
  }
472
475
  }
473
476