c2-mongoose 2.1.407 → 2.1.409

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.
@@ -24,6 +24,7 @@ var BuildAndQueriesFlowItem = /** @class */ (function () {
24
24
  BuildAndQueriesFlowItem.prototype.execute = function (filters, model) {
25
25
  var andQueriesParam = undefined;
26
26
  Object.entries(filters).forEach(function (_a) {
27
+ var _b;
27
28
  var key = _a[0], value = _a[1];
28
29
  if (value !== undefined || value === null) {
29
30
  if ([
@@ -57,7 +58,7 @@ var BuildAndQueriesFlowItem = /** @class */ (function () {
57
58
  return;
58
59
  }
59
60
  if (key.startsWith("$")) {
60
- andQueriesParam = __assign(__assign({}, andQueriesParam), value);
61
+ andQueriesParam = __assign(__assign({}, andQueriesParam), (_b = {}, _b[key] = value, _b));
61
62
  return;
62
63
  }
63
64
  if (typeof value === 'string' && IsValidObjectIdFlowItem_1.default.exec(value) && key !== 'owner' && key !== 'identifier') {
@@ -5,6 +5,7 @@ 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 IsValidObjectIdFlowItem_1 = __importDefault(require("./IsValidObjectIdFlowItem"));
8
9
  var BuildConditionSearchTextFlowItem = /** @class */ (function () {
9
10
  function BuildConditionSearchTextFlowItem() {
10
11
  }
@@ -13,10 +14,22 @@ var BuildConditionSearchTextFlowItem = /** @class */ (function () {
13
14
  var conditions = undefined;
14
15
  var camposString = !filters.searchTextFields ? ExtractFieldsOfTypeFlowItem_1.default.exec(model.schema, 'String') : filters.searchTextFields;
15
16
  if (filters.searchText && camposString) {
16
- var regex = BuildRegexFlowItem_1.default.exec(filters.searchText);
17
17
  conditions = { $or: [] };
18
+ var regex = BuildRegexFlowItem_1.default.exec(filters.searchText);
18
19
  for (var _i = 0, camposString_1 = camposString; _i < camposString_1.length; _i++) {
19
20
  var fieldString = camposString_1[_i];
21
+ if (IsValidObjectIdFlowItem_1.default.exec(camposString)) {
22
+ var conditionAux_1 = {};
23
+ conditionAux_1["$expr"] = {
24
+ "$regexMatch": {
25
+ input: { $toString: "$_id" },
26
+ regex: filters.searchText,
27
+ options: "i" // (opcional) case insensitive
28
+ }
29
+ };
30
+ conditions.$or.push(conditionAux_1);
31
+ continue;
32
+ }
20
33
  var conditionAux = {};
21
34
  conditionAux[fieldString] = { $regex: regex };
22
35
  conditions.$or.push(conditionAux);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.407",
3
+ "version": "2.1.409",
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",
@@ -40,7 +40,7 @@ class BuildAndQueriesFlowItem {
40
40
  }
41
41
 
42
42
  if (key.startsWith("$")) {
43
- andQueriesParam = { ...andQueriesParam, ...value }
43
+ andQueriesParam = { ...andQueriesParam, ...{ [key]: value} }
44
44
  return
45
45
  }
46
46
  if (typeof value === 'string' && IsValidObjectIdFlowItem.exec(value as string) && key !== 'owner' && key !== 'identifier') {
@@ -1,6 +1,7 @@
1
1
  import mongoose from "mongoose"
2
2
  import BuildRegexFlowItem from "../../v2/item/BuildRegexFlowItem"
3
3
  import ExtractFieldsOfTypeFlowItem from "../../v2/item/ExtractFieldsOfTypeFlowItem"
4
+ import IsValidObjectIdFlowItem from "./IsValidObjectIdFlowItem"
4
5
 
5
6
  class BuildConditionSearchTextFlowItem {
6
7
  execute(filters: any, model: mongoose.Model<any>) {
@@ -8,9 +9,25 @@ class BuildConditionSearchTextFlowItem {
8
9
  let conditions = undefined
9
10
  const camposString = !filters.searchTextFields ? ExtractFieldsOfTypeFlowItem.exec(model.schema, 'String') : filters.searchTextFields
10
11
  if (filters.searchText && camposString) {
11
- let regex = BuildRegexFlowItem.exec(filters.searchText)
12
12
  conditions = { $or: [] as any }
13
+ let regex = BuildRegexFlowItem.exec(filters.searchText)
14
+
13
15
  for (let fieldString of camposString) {
16
+
17
+ if (IsValidObjectIdFlowItem.exec(camposString)) {
18
+ let conditionAux: { [key: string]: any } = {}
19
+ conditionAux["$expr"] = {
20
+ "$regexMatch": {
21
+ input: { $toString: "$_id" }, // converte ObjectId -> string
22
+ regex: filters.searchText, // substring a procurar
23
+ options: "i" // (opcional) case insensitive
24
+ }
25
+ }
26
+ conditions.$or.push(conditionAux)
27
+ continue
28
+ }
29
+
30
+
14
31
  let conditionAux: { [key: string]: any } = {}
15
32
  conditionAux[fieldString] = { $regex: regex }
16
33