c2-mongoose 2.1.65 → 2.1.67

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.
@@ -135,11 +135,20 @@ var SearchFlow = /** @class */ (function () {
135
135
  };
136
136
  SearchFlow.prototype.buildPopulateArray = function () {
137
137
  var populates = [];
138
- for (var _i = 0, _a = this.populate; _i < _a.length; _i++) {
139
- var property = _a[_i];
138
+ var _loop_1 = function () {
140
139
  var _b = property.split('.'), first = _b[0], rest = _b.slice(1);
141
140
  var nested = rest.join('.');
142
- populates.push(this.buildPath(first, nested));
141
+ var populate = this_1.buildPath(first, nested);
142
+ if (Array.isArray(this_1.select)) {
143
+ var selects = this_1.select.filter(function (sel) { return sel.startsWith("".concat(first, ".")); });
144
+ populate.select = selects.join(" ");
145
+ }
146
+ populates.push(populate);
147
+ };
148
+ var this_1 = this;
149
+ for (var _i = 0, _a = this.populate; _i < _a.length; _i++) {
150
+ var property = _a[_i];
151
+ _loop_1();
143
152
  }
144
153
  this.populate = populates;
145
154
  };
@@ -204,6 +213,7 @@ var SearchFlow = /** @class */ (function () {
204
213
  case 1:
205
214
  result = _c.sent();
206
215
  items = result[0].items;
216
+ if (!((0, Utils_1.isNotEmpty)(this.populate) && Array.isArray(this.populate))) return [3 /*break*/, 5];
207
217
  _i = 0, _b = this.populate;
208
218
  _c.label = 2;
209
219
  case 2:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.65",
3
+ "version": "2.1.67",
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",
@@ -69,7 +69,12 @@ abstract class SearchFlow {
69
69
  for (var property of this.populate) {
70
70
  let [first, ...rest] = property.split('.')
71
71
  let nested = rest.join('.')
72
- populates.push(this.buildPath(first, nested))
72
+ let populate = this.buildPath(first, nested)
73
+ if (Array.isArray(this.select)) {
74
+ let selects = (this.select as []).filter((sel: string) => sel.startsWith(`${first}.`))
75
+ populate.select = selects.join(" ")
76
+ }
77
+ populates.push(populate)
73
78
  }
74
79
 
75
80
  this.populate = populates
@@ -136,8 +141,11 @@ abstract class SearchFlow {
136
141
  ).session(options?.session as ClientSession)
137
142
 
138
143
  var items = result[0].items
139
- for (var populate of this.populate) {
140
- items = await model.populate(result[0].items, populate)
144
+
145
+ if (isNotEmpty(this.populate) && Array.isArray(this.populate)) {
146
+ for (var populate of this.populate) {
147
+ items = await model.populate(result[0].items, populate)
148
+ }
141
149
  }
142
150
 
143
151
  return {