c2-mongoose 2.1.261 → 2.1.264

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.
@@ -88,9 +88,9 @@ var SearcherFlow = /** @class */ (function () {
88
88
  SearcherFlow.prototype.search = function (options) {
89
89
  var _a;
90
90
  return __awaiter(this, void 0, void 0, function () {
91
- var stagesItems, stagesPaging, stagesMetadata, facet, _i, stagesMetadata_1, metadata, result, _b, resultAux;
92
- return __generator(this, function (_c) {
93
- switch (_c.label) {
91
+ var stagesItems, stagesPaging, stagesMetadata, facet, _b, stagesMetadata_1, metadata, result, _c, resultAux;
92
+ return __generator(this, function (_d) {
93
+ switch (_d.label) {
94
94
  case 0:
95
95
  stagesItems = [];
96
96
  if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
@@ -148,8 +148,8 @@ var SearcherFlow = /** @class */ (function () {
148
148
  facet.items = stagesItems;
149
149
  facet.paging = stagesPaging;
150
150
  }
151
- for (_i = 0, stagesMetadata_1 = stagesMetadata; _i < stagesMetadata_1.length; _i++) {
152
- metadata = stagesMetadata_1[_i];
151
+ for (_b = 0, stagesMetadata_1 = stagesMetadata; _b < stagesMetadata_1.length; _b++) {
152
+ metadata = stagesMetadata_1[_b];
153
153
  facet[metadata.id] = metadata.conditions;
154
154
  }
155
155
  return [4 /*yield*/, this.model.aggregate([
@@ -163,13 +163,13 @@ var SearcherFlow = /** @class */ (function () {
163
163
  }
164
164
  }).session(options === null || options === void 0 ? void 0 : options.session)];
165
165
  case 1:
166
- result = _c.sent();
166
+ result = _d.sent();
167
167
  if (!(0, Utils_1.isNotEmpty)(this.populate)) return [3 /*break*/, 3];
168
- _b = result[0];
168
+ _c = result[0];
169
169
  return [4 /*yield*/, this.model.populate(result[0].items, BuildPopulateSingleFlowItem_1.default.buildPopulate(this.model, this.populate, this.select))];
170
170
  case 2:
171
- _b.items = _c.sent();
172
- _c.label = 3;
171
+ _c.items = _d.sent();
172
+ _d.label = 3;
173
173
  case 3:
174
174
  resultAux = this.transformObject(result[0]);
175
175
  return [2 /*return*/, resultAux];
@@ -216,6 +216,7 @@ var SearcherFlow = /** @class */ (function () {
216
216
  var camposString = this.extractFieldsOfType(this.model.schema, 'String');
217
217
  var filters = { $and: [] };
218
218
  Object.entries(objectSearch).forEach(function (_a) {
219
+ var _b, _c, _d;
219
220
  var key = _a[0], value = _a[1];
220
221
  if ((0, Utils_1.isNotEmpty)(value)) {
221
222
  var condition = {};
@@ -279,10 +280,19 @@ var SearcherFlow = /** @class */ (function () {
279
280
  filters.$and.push(condition);
280
281
  }
281
282
  else {
282
- if (!Array.isArray(value)) {
283
- condition[key] = value;
283
+ if (((_d = (_c = (_b = _this.model) === null || _b === void 0 ? void 0 : _b.schema) === null || _c === void 0 ? void 0 : _c.paths[key]) === null || _d === void 0 ? void 0 : _d.instance) === 'Array') {
284
+ if (!Array.isArray(value)) {
285
+ value = [value];
286
+ }
287
+ if (key.startsWith("notIn")) {
288
+ key = key.replace("notIn", "");
289
+ condition[key] = { $nin: value };
290
+ }
291
+ else {
292
+ condition[key] = { $in: value };
293
+ }
284
294
  }
285
- else {
295
+ else if (Array.isArray(value)) {
286
296
  var arr = [];
287
297
  for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
288
298
  var val = value_1[_i];
@@ -299,6 +309,9 @@ var SearcherFlow = /** @class */ (function () {
299
309
  condition[key] = { $in: arr };
300
310
  }
301
311
  }
312
+ else {
313
+ condition[key] = value;
314
+ }
302
315
  filters.$and.push(condition);
303
316
  }
304
317
  }
@@ -306,8 +319,8 @@ var SearcherFlow = /** @class */ (function () {
306
319
  if ((0, Utils_1.isNotEmpty)(this.searchText) && (0, Utils_1.isNotEmpty)(camposString)) {
307
320
  var regex = this.buildRegex(this.searchText);
308
321
  var conditions = { $or: [] };
309
- for (var _i = 0, camposString_1 = camposString; _i < camposString_1.length; _i++) {
310
- var fieldString = camposString_1[_i];
322
+ for (var _a = 0, camposString_1 = camposString; _a < camposString_1.length; _a++) {
323
+ var fieldString = camposString_1[_a];
311
324
  var conditionAux = {};
312
325
  conditionAux[fieldString] = { $regex: regex };
313
326
  conditions.$or.push(conditionAux);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.261",
3
+ "version": "2.1.264",
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",
@@ -9,7 +9,7 @@
9
9
  "build": "tsc --skipLibCheck",
10
10
  "preversion": "tsc --skipLibCheck",
11
11
  "postversion": "git push && git push --tags && npm publish",
12
- "publish-patch": "npm version patch",
12
+ "publish-patch": "npm version patch --force",
13
13
  "publish-minor": "npm version minor",
14
14
  "publish-major": "npm version major"
15
15
  },
@@ -44,7 +44,7 @@ class SearcherFlow<D> {
44
44
  async search(options: SearchOptions): Promise<SearchResponse<D>> {
45
45
 
46
46
  let stagesItems: any[] = []
47
-
47
+
48
48
  if (isNotEmpty(options.pipelines)) {
49
49
  stagesItems.push(...options.pipelines)
50
50
  }
@@ -60,7 +60,7 @@ class SearcherFlow<D> {
60
60
  }
61
61
  }
62
62
  stagesItems.push({ $sort: this.buildOrdenation() })
63
-
63
+
64
64
  ///
65
65
  let stagesPaging: any[] = []
66
66
  // if (isNotEmpty(options.pipelines)) {
@@ -251,24 +251,36 @@ class SearcherFlow<D> {
251
251
  }
252
252
 
253
253
  else {
254
- if (!Array.isArray(value)) {
255
- condition[key] = value
256
- } else {
257
- let arr = []
258
- for (let val of value) {
259
- if (typeof val === 'string' && this.isValidObjectId(val as string)) {
260
- val = new Types.ObjectId(val as string)
261
- }
262
- arr.push(val)
254
+ if (this.model?.schema?.paths[key]?.instance === 'Array') {
255
+ if (!Array.isArray(value)) {
256
+ value = [value]
263
257
  }
264
258
 
265
259
  if (key.startsWith("notIn")) {
266
- key = key.replace("notIn", "")
267
- condition[key] = { $nin: arr }
268
- } else {
269
- condition[key] = { $in: arr }
260
+ key = key.replace("notIn", "");
261
+ condition[key] = { $nin: value };
270
262
  }
271
-
263
+ else {
264
+ condition[key] = { $in: value };
265
+ }
266
+ } else if (Array.isArray(value)) {
267
+ var arr = [];
268
+ for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
269
+ var val = value_1[_i];
270
+ if (typeof val === 'string' && this.isValidObjectId(val)) {
271
+ val = new Types.ObjectId(val);
272
+ }
273
+ arr.push(val);
274
+ }
275
+ if (key.startsWith("notIn")) {
276
+ key = key.replace("notIn", "");
277
+ condition[key] = { $nin: arr };
278
+ }
279
+ else {
280
+ condition[key] = { $in: arr };
281
+ }
282
+ } else {
283
+ condition[key] = value;
272
284
  }
273
285
  filters.$and.push(condition)
274
286
  }