c2-mongoose 2.1.437 → 2.1.438

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.
@@ -5,20 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var BuildRegexFlowItem_1 = __importDefault(require("../../v2/item/BuildRegexFlowItem"));
7
7
  var ExtractFieldsOfTypeFlowItem_1 = __importDefault(require("../../v2/item/ExtractFieldsOfTypeFlowItem"));
8
+ var lodash_1 = require("lodash");
8
9
  var BuildConditionSearchTextFlowItem = /** @class */ (function () {
9
10
  function BuildConditionSearchTextFlowItem() {
10
11
  }
11
12
  BuildConditionSearchTextFlowItem.prototype.execute = function (filters, model) {
12
- var _a;
13
+ var _a, _b, _c;
13
14
  // Recuperar todos os campos do tipo String
14
15
  var conditions = undefined;
15
- var camposString = !filters.searchTextFields ? ExtractFieldsOfTypeFlowItem_1.default.exec(model.schema, 'String') : filters.searchTextFields;
16
+ var searchTextFields = (0, lodash_1.isArray)(filters.searchTextFields) ? filters.searchTextFields : (_b = (_a = filters.searchTextFields) === null || _a === void 0 ? void 0 : _a.split(',').map(function (field) { return field.trim(); }).filter(function (field) { return field.length > 0; })) !== null && _b !== void 0 ? _b : [];
17
+ var camposString = !(searchTextFields === null || searchTextFields === void 0 ? void 0 : searchTextFields.length) ? ExtractFieldsOfTypeFlowItem_1.default.exec(model.schema, 'String') : searchTextFields;
16
18
  if (filters.searchText && camposString) {
17
19
  conditions = { $or: [] };
18
20
  var regex = BuildRegexFlowItem_1.default.exec(filters.searchText);
19
21
  for (var _i = 0, camposString_1 = camposString; _i < camposString_1.length; _i++) {
20
22
  var fieldString = camposString_1[_i];
21
- if (fieldString.endsWith("_id") || ((_a = model.schema.path(fieldString)) === null || _a === void 0 ? void 0 : _a.instance) === "ObjectId") {
23
+ if (fieldString.endsWith("_id") || ((_c = model.schema.path(fieldString)) === null || _c === void 0 ? void 0 : _c.instance) === "ObjectId") {
22
24
  var conditionAux_1 = {};
23
25
  conditionAux_1["$expr"] = {
24
26
  "$regexMatch": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.437",
3
+ "version": "2.1.438",
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",
@@ -2,12 +2,17 @@ import mongoose from "mongoose"
2
2
  import BuildRegexFlowItem from "../../v2/item/BuildRegexFlowItem"
3
3
  import ExtractFieldsOfTypeFlowItem from "../../v2/item/ExtractFieldsOfTypeFlowItem"
4
4
  import IsValidObjectIdFlowItem from "./IsValidObjectIdFlowItem"
5
+ import { isArray } from "lodash"
5
6
 
6
7
  class BuildConditionSearchTextFlowItem {
7
8
  execute(filters: any, model: mongoose.Model<any>) {
8
9
  // Recuperar todos os campos do tipo String
9
10
  let conditions = undefined
10
- const camposString = !filters.searchTextFields ? ExtractFieldsOfTypeFlowItem.exec(model.schema, 'String') : filters.searchTextFields
11
+
12
+ const searchTextFields = isArray(filters.searchTextFields) ? filters.searchTextFields : filters.searchTextFields?.split(',').map((field: string) => field.trim()).filter((field: string) => field.length > 0) ?? [];
13
+
14
+ const camposString = !searchTextFields?.length ? ExtractFieldsOfTypeFlowItem.exec(model.schema, 'String') : searchTextFields
15
+
11
16
  if (filters.searchText && camposString) {
12
17
  conditions = { $or: [] as any }
13
18
  let regex = BuildRegexFlowItem.exec(filters.searchText)