c2-mongoose 2.1.251 → 2.1.253

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.
@@ -92,7 +92,6 @@ var SearcherFlow = /** @class */ (function () {
92
92
  switch (_b.label) {
93
93
  case 0:
94
94
  stagesItems = [];
95
- stagesPaging = [];
96
95
  if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
97
96
  stagesItems.push.apply(stagesItems, options.pipelines);
98
97
  }
@@ -105,12 +104,15 @@ var SearcherFlow = /** @class */ (function () {
105
104
  stagesItems.push({ $project: BuildSelectSingleFlowItem_1.default.build(this.model, this.select) });
106
105
  }
107
106
  stagesItems.push({ $sort: this.buildOrdenation() });
108
- if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
109
- stagesPaging.push.apply(stagesPaging, options.pipelines);
110
- }
111
- if ((0, Utils_1.isNotEmpty)(options.unions)) {
112
- stagesPaging.push.apply(stagesPaging, options.unions);
113
- }
107
+ }
108
+ stagesPaging = [];
109
+ // if (isNotEmpty(options.pipelines)) {
110
+ // stagesPaging.push(...options.pipelines)
111
+ // }
112
+ if ((0, Utils_1.isNotEmpty)(options.unions)) {
113
+ stagesPaging.push.apply(stagesPaging, options.unions);
114
+ }
115
+ if ((0, Utils_1.isEmpty)(options.paging)) {
114
116
  stagesPaging.push({ $match: this.filters });
115
117
  stagesPaging.push({ $count: "total" });
116
118
  stagesPaging.push({
@@ -129,6 +131,9 @@ var SearcherFlow = /** @class */ (function () {
129
131
  }
130
132
  });
131
133
  }
134
+ else {
135
+ stagesPaging = __spreadArray(__spreadArray([], stagesPaging, true), options.paging, true);
136
+ }
132
137
  if (this.pageable === true) {
133
138
  stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 });
134
139
  stagesItems.push({ $limit: this.limit });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.251",
3
+ "version": "2.1.253",
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",
@@ -44,7 +44,7 @@ class SearcherFlow<D> {
44
44
  async search(options: SearchOptions): Promise<SearchResponse<D>> {
45
45
 
46
46
  let stagesItems: any[] = []
47
- let stagesPaging: any[] = []
47
+
48
48
  if (isNotEmpty(options.pipelines)) {
49
49
  stagesItems.push(...options.pipelines)
50
50
  }
@@ -59,14 +59,19 @@ class SearcherFlow<D> {
59
59
  stagesItems.push({ $project: BuildSelectSingleFlowItem.build(this.model, this.select) })
60
60
  }
61
61
  stagesItems.push({ $sort: this.buildOrdenation() })
62
+ }
63
+
64
+ ///
65
+ let stagesPaging: any[] = []
66
+ // if (isNotEmpty(options.pipelines)) {
67
+ // stagesPaging.push(...options.pipelines)
68
+ // }
69
+ if (isNotEmpty(options.unions)) {
70
+ stagesPaging.push(...options.unions)
71
+ }
62
72
 
63
- if (isNotEmpty(options.pipelines)) {
64
- stagesPaging.push(...options.pipelines)
65
- }
66
- if (isNotEmpty(options.unions)) {
67
- stagesPaging.push(...options.unions)
68
- }
69
73
 
74
+ if (isEmpty(options.paging)) {
70
75
  stagesPaging.push({ $match: this.filters })
71
76
  stagesPaging.push({ $count: "total" })
72
77
  stagesPaging.push({
@@ -84,6 +89,8 @@ class SearcherFlow<D> {
84
89
  endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
85
90
  }
86
91
  })
92
+ } else {
93
+ stagesPaging = [...stagesPaging, ...options.paging]
87
94
  }
88
95
 
89
96
  if (this.pageable === true) {
@@ -19,6 +19,7 @@ declare interface PipelineStage {
19
19
  declare interface SearchOptions {
20
20
  unions: PipelineStage[],
21
21
  pipelines: PipelineStage[],
22
+ paging: PipelineStage[],
22
23
  metadata: PipelineStage[],
23
24
  session?: ClientSession
24
25
  }