c2-mongoose 2.1.101 → 2.1.103

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.
@@ -187,7 +187,7 @@ var SearchFlow = /** @class */ (function () {
187
187
  SearchFlow.prototype.searchPageable = function (model, options) {
188
188
  var _a;
189
189
  return __awaiter(this, void 0, void 0, function () {
190
- var stagesItems, stagesPaging, result, items, _i, _b, populate;
190
+ var stagesItems, stagesPaging, stagesMetadata, result, items, _i, _b, populate;
191
191
  return __generator(this, function (_c) {
192
192
  switch (_c.label) {
193
193
  case 0:
@@ -210,11 +210,16 @@ var SearchFlow = /** @class */ (function () {
210
210
  }
211
211
  stagesPaging.push({ $count: "total" });
212
212
  stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } });
213
+ stagesMetadata = [];
214
+ if ((0, Utils_1.isNotEmpty)(options.metadata)) {
215
+ stagesMetadata.push.apply(stagesMetadata, options.metadata);
216
+ }
213
217
  return [4 /*yield*/, model.aggregate([
214
218
  {
215
219
  $facet: {
216
220
  items: stagesItems,
217
- paging: stagesPaging
221
+ paging: stagesPaging,
222
+ metadata: stagesMetadata
218
223
  }
219
224
  }
220
225
  ]).session(options === null || options === void 0 ? void 0 : options.session)];
@@ -460,13 +465,15 @@ var SearchFlow = /** @class */ (function () {
460
465
  condition[key] = value;
461
466
  }
462
467
  else {
468
+ var arr = [];
463
469
  for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
464
470
  var val = value_1[_i];
465
471
  if (typeof val === 'string' && _this.isValidObjectId(val)) {
466
472
  val = new mongoose_1.Types.ObjectId(val);
467
473
  }
474
+ arr.push(val);
468
475
  }
469
- condition[key] = { $in: value };
476
+ condition[key] = { $in: arr };
470
477
  }
471
478
  filters.$and.push(condition);
472
479
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.101",
3
+ "version": "2.1.103",
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,15 +123,6 @@ abstract class SearchFlow {
123
123
  }
124
124
 
125
125
  async searchPageable(model: mongoose.Model<any>, options: SearchOptions) {
126
- // let stagesItems = [
127
- // { $match: this.filters },
128
- // isNotEmpty(options.unions) ? options.unions : undefined,
129
- // this.projection ? { $project: this.projection } : { $addFields: {} },
130
- // ...options.pipelines,
131
- // { $sort: this.sort },
132
- // { $skip: ((this.page - 1) * this.limit) || 0 },
133
- // { $limit: this.limit },
134
- // ]
135
126
 
136
127
  let stagesItems: any[] = [{ $match: this.filters }]
137
128
 
@@ -159,13 +150,18 @@ abstract class SearchFlow {
159
150
  stagesPaging.push({ $count: "total" })
160
151
  stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } })
161
152
 
153
+ let stagesMetadata: any[] = []
154
+ if (isNotEmpty(options.metadata)) {
155
+ stagesMetadata.push(...options.metadata)
156
+ }
162
157
 
163
158
  const result = await model.aggregate(
164
159
  [
165
160
  {
166
161
  $facet: {
167
162
  items: stagesItems,
168
- paging: stagesPaging
163
+ paging: stagesPaging,
164
+ metadata: stagesMetadata
169
165
  }
170
166
  }
171
167
  ]
@@ -385,13 +381,15 @@ abstract class SearchFlow {
385
381
  if (!Array.isArray(value)) {
386
382
  condition[key] = value
387
383
  } else {
388
- for(let val of value) {
384
+ let arr = []
385
+ for (let val of value) {
389
386
  if (typeof val === 'string' && this.isValidObjectId(val as string)) {
390
387
  val = new Types.ObjectId(val as string)
391
388
  }
389
+ arr.push(val)
392
390
  }
393
391
 
394
- condition[key] = { $in: value }
392
+ condition[key] = { $in: arr }
395
393
  }
396
394
  filters.$and.push(condition)
397
395
  }
@@ -18,6 +18,7 @@ declare interface PipelineStage {
18
18
  declare interface SearchOptions {
19
19
  unions: PipelineStage[],
20
20
  pipelines: PipelineStage[],
21
+ metadata: PipelineStage[],
21
22
  session?: ClientSession
22
23
  }
23
24