c2-mongoose 2.1.127 → 2.1.129

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.
@@ -161,16 +161,17 @@ var SearchFlow = /** @class */ (function () {
161
161
  return __generator(this, function (_d) {
162
162
  switch (_d.label) {
163
163
  case 0:
164
- stagesItems = [{ $match: this.filters }];
164
+ stagesItems = [];
165
+ if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
166
+ stagesItems.push.apply(stagesItems, options.pipelines);
167
+ }
165
168
  if ((0, Utils_1.isNotEmpty)(options.unions)) {
166
169
  stagesItems.push.apply(stagesItems, options.unions);
167
170
  }
171
+ stagesItems.push({ $match: this.filters });
168
172
  if ((0, Utils_1.isNotEmpty)(this.projection)) {
169
173
  stagesItems.push({ $project: this.projection });
170
174
  }
171
- if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
172
- stagesItems.push.apply(stagesItems, options.pipelines);
173
- }
174
175
  stagesItems.push({ $sort: this.sort });
175
176
  stagesItems.push({ $limit: (_a = this.limit) !== null && _a !== void 0 ? _a : 50 });
176
177
  stagesMetadata = [];
@@ -218,10 +219,14 @@ var SearchFlow = /** @class */ (function () {
218
219
  return __generator(this, function (_c) {
219
220
  switch (_c.label) {
220
221
  case 0:
221
- stagesItems = [{ $match: this.filters }];
222
+ stagesItems = [];
223
+ if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
224
+ stagesItems.push.apply(stagesItems, options.pipelines);
225
+ }
222
226
  if ((0, Utils_1.isNotEmpty)(options.unions)) {
223
227
  stagesItems.push.apply(stagesItems, options.unions);
224
228
  }
229
+ stagesItems.push({ $match: this.filters });
225
230
  if ((0, Utils_1.isNotEmpty)(this.projection)) {
226
231
  stagesItems.push({ $project: this.projection });
227
232
  }
@@ -231,10 +236,14 @@ var SearchFlow = /** @class */ (function () {
231
236
  stagesItems.push({ $sort: this.sort });
232
237
  stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 });
233
238
  stagesItems.push({ $limit: this.limit });
234
- stagesPaging = [{ $match: this.filters }];
239
+ stagesPaging = [];
240
+ if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
241
+ stagesPaging.push.apply(stagesPaging, options.pipelines);
242
+ }
235
243
  if ((0, Utils_1.isNotEmpty)(options.unions)) {
236
244
  stagesPaging.push.apply(stagesPaging, options.unions);
237
245
  }
246
+ stagesPaging.push({ $match: this.filters });
238
247
  stagesPaging.push({ $count: "total" });
239
248
  stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } });
240
249
  stagesMetadata = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.127",
3
+ "version": "2.1.129",
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",
@@ -123,19 +123,21 @@ abstract class SearchFlow {
123
123
 
124
124
  async searchNoPageable(model: mongoose.Model<any>, options: SearchOptions) {
125
125
 
126
- let stagesItems: any[] = [{ $match: this.filters }]
126
+ let stagesItems: any[] = []
127
127
 
128
+ if (isNotEmpty(options.pipelines)) {
129
+ stagesItems.push(...options.pipelines)
130
+ }
128
131
  if (isNotEmpty(options.unions)) {
129
132
  stagesItems.push(...options.unions)
130
133
  }
131
134
 
135
+ stagesItems.push({ $match: this.filters })
136
+
132
137
  if (isNotEmpty(this.projection)) {
133
138
  stagesItems.push({ $project: this.projection })
134
139
  }
135
140
 
136
- if (isNotEmpty(options.pipelines)) {
137
- stagesItems.push(...options.pipelines)
138
- }
139
141
 
140
142
  stagesItems.push({ $sort: this.sort })
141
143
  stagesItems.push({ $limit: this.limit ?? 50 })
@@ -176,12 +178,17 @@ abstract class SearchFlow {
176
178
 
177
179
  async searchPageable(model: mongoose.Model<any>, options: SearchOptions) {
178
180
 
179
- let stagesItems: any[] = [{ $match: this.filters }]
181
+ let stagesItems: any[] = []
180
182
 
183
+ if (isNotEmpty(options.pipelines)) {
184
+ stagesItems.push(...options.pipelines)
185
+ }
181
186
  if (isNotEmpty(options.unions)) {
182
187
  stagesItems.push(...options.unions)
183
188
  }
184
189
 
190
+ stagesItems.push({ $match: this.filters })
191
+
185
192
  if (isNotEmpty(this.projection)) {
186
193
  stagesItems.push({ $project: this.projection })
187
194
  }
@@ -195,10 +202,15 @@ abstract class SearchFlow {
195
202
  stagesItems.push({ $limit: this.limit })
196
203
 
197
204
 
198
- let stagesPaging: any[] = [{ $match: this.filters }]
205
+ let stagesPaging: any[] = []
206
+
207
+ if (isNotEmpty(options.pipelines)) {
208
+ stagesPaging.push(...options.pipelines)
209
+ }
199
210
  if (isNotEmpty(options.unions)) {
200
211
  stagesPaging.push(...options.unions)
201
212
  }
213
+ stagesPaging.push({ $match: this.filters })
202
214
  stagesPaging.push({ $count: "total" })
203
215
  stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } })
204
216