c2-mongoose 2.1.64 → 2.1.66

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.
@@ -173,9 +173,9 @@ var SearchFlow = /** @class */ (function () {
173
173
  SearchFlow.prototype.searchPageable = function (model, options) {
174
174
  var _a;
175
175
  return __awaiter(this, void 0, void 0, function () {
176
- var stagesItems, result;
177
- return __generator(this, function (_b) {
178
- switch (_b.label) {
176
+ var stagesItems, result, items, _i, _b, populate;
177
+ return __generator(this, function (_c) {
178
+ switch (_c.label) {
179
179
  case 0:
180
180
  stagesItems = __spreadArray([
181
181
  { $match: this.filters },
@@ -202,11 +202,25 @@ var SearchFlow = /** @class */ (function () {
202
202
  }
203
203
  ]).session(options === null || options === void 0 ? void 0 : options.session)];
204
204
  case 1:
205
- result = _b.sent();
206
- return [2 /*return*/, {
207
- items: result[0].items,
208
- paging: ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.paging[0]) || { total: 0, page: 1, limit: this.limit }
209
- }];
205
+ result = _c.sent();
206
+ items = result[0].items;
207
+ if (!((0, Utils_1.isNotEmpty)(this.populate) && Array.isArray(this.populate))) return [3 /*break*/, 5];
208
+ _i = 0, _b = this.populate;
209
+ _c.label = 2;
210
+ case 2:
211
+ if (!(_i < _b.length)) return [3 /*break*/, 5];
212
+ populate = _b[_i];
213
+ return [4 /*yield*/, model.populate(result[0].items, populate)];
214
+ case 3:
215
+ items = _c.sent();
216
+ _c.label = 4;
217
+ case 4:
218
+ _i++;
219
+ return [3 /*break*/, 2];
220
+ case 5: return [2 /*return*/, {
221
+ items: items,
222
+ paging: ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.paging[0]) || { total: 0, page: 1, limit: this.limit }
223
+ }];
210
224
  }
211
225
  });
212
226
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.64",
3
+ "version": "2.1.66",
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",
@@ -134,8 +134,17 @@ abstract class SearchFlow {
134
134
  }
135
135
  ]
136
136
  ).session(options?.session as ClientSession)
137
+
138
+ var items = result[0].items
139
+
140
+ if (isNotEmpty(this.populate) && Array.isArray(this.populate)) {
141
+ for (var populate of this.populate) {
142
+ items = await model.populate(result[0].items, populate)
143
+ }
144
+ }
145
+
137
146
  return {
138
- items: result[0].items,
147
+ items,
139
148
  paging: result[0]?.paging[0] || { total: 0, page: 1, limit: this.limit }
140
149
  }
141
150
  }