c2-mongoose 2.1.465 → 2.1.467

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.
@@ -15,9 +15,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var mongoose_1 = require("mongoose");
18
- var BuildConditionFlowItem_1 = __importDefault(require("../../v2/item/BuildConditionFlowItem"));
18
+ var BuildConditionFlowItem_1 = __importDefault(require("../../v3/item/BuildConditionFlowItem"));
19
19
  var BuildConditionSearchTextFlowItem_1 = __importDefault(require("./BuildConditionSearchTextFlowItem"));
20
- var IsValidObjectIdFlowItem_1 = __importDefault(require("../../v2/item/IsValidObjectIdFlowItem"));
20
+ var IsValidObjectIdFlowItem_1 = __importDefault(require("../../v3/item/IsValidObjectIdFlowItem"));
21
21
  var BuildAndQueriesFlowItem = /** @class */ (function () {
22
22
  function BuildAndQueriesFlowItem() {
23
23
  }
@@ -1,6 +1,7 @@
1
1
  import mongoose from "mongoose";
2
2
  declare class BuildConditionFlowItem {
3
3
  exec(key: string, value: any, model: mongoose.Model<any>): any;
4
+ replaceLast(str: string, target: string, replacement: string): string;
4
5
  }
5
6
  declare const _default: BuildConditionFlowItem;
6
7
  export default _default;
@@ -26,7 +26,7 @@ var BuildConditionFlowItem = /** @class */ (function () {
26
26
  var _b, _c;
27
27
  var condition = {};
28
28
  if (key.endsWith('DateRange')) {
29
- var fieldName = key.replace('Range', '');
29
+ var fieldName = this.replaceLast(key, 'Range', '');
30
30
  var values = value;
31
31
  if (values[0]) {
32
32
  var momentValue = (0, moment_1.default)(values[0]);
@@ -44,7 +44,7 @@ var BuildConditionFlowItem = /** @class */ (function () {
44
44
  }
45
45
  }
46
46
  else if (key.endsWith('DateTimeRange')) {
47
- var fieldName = key.replace('Range', '');
47
+ var fieldName = this.replaceLast(key, 'Range', '');
48
48
  var values = value;
49
49
  if (values[0]) {
50
50
  var momentValue = (0, moment_1.default)(values[0]);
@@ -56,7 +56,7 @@ var BuildConditionFlowItem = /** @class */ (function () {
56
56
  }
57
57
  }
58
58
  else if (key.endsWith('Range')) {
59
- var fieldName = key.replace('Range', '');
59
+ var fieldName = this.replaceLast(key, 'Range', '');
60
60
  var values = value;
61
61
  if (values[0]) {
62
62
  condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $gte: Number(values[0]) });
@@ -66,31 +66,43 @@ var BuildConditionFlowItem = /** @class */ (function () {
66
66
  }
67
67
  }
68
68
  else if (key.endsWith('Like')) {
69
- var fieldName = key.replace('Like', '');
69
+ var fieldName = this.replaceLast(key, 'Like', '');
70
70
  condition[fieldName] = BuildRegexFlowItem_1.default.exec(value); //{ $regex: value as any, $options: 'i' }
71
71
  }
72
72
  else if (key.endsWith("AtLeastOneExists")) {
73
- key = key.replace("AtLeastOneExists", "");
73
+ key = this.replaceLast(key, "AtLeastOneExists", "");
74
74
  var fields = key.split('.');
75
75
  if (!fields)
76
76
  return condition;
77
77
  condition[fields[0]] = { $elemMatch: (_a = {}, _a[fields[1]] = { $exists: value }, _a) };
78
78
  }
79
79
  else if (key.endsWith('Exists')) {
80
- var fieldName = key.replace('Exists', '');
80
+ var fieldName = this.replaceLast(key, 'Exists', '');
81
81
  condition[fieldName] = { $exists: value };
82
82
  }
83
83
  else if (key.endsWith("IsEmpty")) {
84
- key = key.replace("IsEmpty", "");
84
+ key = this.replaceLast(key, "IsEmpty", "");
85
85
  condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
86
86
  }
87
+ else if (key.endsWith("Minimum")) {
88
+ key = this.replaceLast(key, "Minimum", "");
89
+ condition[key] = {
90
+ $gte: Number(value)
91
+ };
92
+ }
93
+ else if (key.endsWith("Maximum")) {
94
+ key = this.replaceLast(key, "Maximum", "");
95
+ condition[key] = {
96
+ $lte: Number(value)
97
+ };
98
+ }
87
99
  else if (key.endsWith("NotIn")) {
88
- key = key.replace("NotIn", "");
100
+ key = this.replaceLast(key, "NotIn", "");
89
101
  var valuesArr = value === null || value === void 0 ? void 0 : value.trim().split(',').map(function (v) { return v.trim(); });
90
102
  condition[key] = { $nin: valuesArr };
91
103
  }
92
104
  else if (key.endsWith("In")) {
93
- key = key.replace("In", "");
105
+ key = this.replaceLast(key, "In", "");
94
106
  var valuesArr = value === null || value === void 0 ? void 0 : value.trim().split(',').map(function (v) { return v.trim(); });
95
107
  condition[key] = { $in: valuesArr };
96
108
  }
@@ -105,7 +117,7 @@ var BuildConditionFlowItem = /** @class */ (function () {
105
117
  }
106
118
  });
107
119
  if (key.endsWith("NotIn")) {
108
- key = key.replace("NotIn", "");
120
+ key = this.replaceLast(key, "NotIn", "");
109
121
  condition[key] = { $nin: value };
110
122
  }
111
123
  else {
@@ -122,7 +134,7 @@ var BuildConditionFlowItem = /** @class */ (function () {
122
134
  arr.push(val);
123
135
  }
124
136
  if (key.endsWith("NotIn")) {
125
- key = key.replace("NotIn", "");
137
+ key = this.replaceLast(key, "NotIn", "");
126
138
  condition[key] = { $nin: arr };
127
139
  }
128
140
  else {
@@ -135,6 +147,14 @@ var BuildConditionFlowItem = /** @class */ (function () {
135
147
  }
136
148
  return condition;
137
149
  };
150
+ BuildConditionFlowItem.prototype.replaceLast = function (str, target, replacement) {
151
+ var index = str.lastIndexOf(target);
152
+ if (index === -1)
153
+ return str;
154
+ return str.substring(0, index) +
155
+ replacement +
156
+ str.substring(index + target.length);
157
+ };
138
158
  return BuildConditionFlowItem;
139
159
  }());
140
160
  exports.default = new BuildConditionFlowItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.465",
3
+ "version": "2.1.467",
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",
@@ -1,7 +1,7 @@
1
1
  import mongoose, { Types } from "mongoose"
2
- import BuildConditionFlowItem from "../../v2/item/BuildConditionFlowItem"
2
+ import BuildConditionFlowItem from "../../v3/item/BuildConditionFlowItem"
3
3
  import BuildConditionSearchTextFlowItem from "./BuildConditionSearchTextFlowItem"
4
- import IsValidObjectIdFlowItem from "../../v2/item/IsValidObjectIdFlowItem"
4
+ import IsValidObjectIdFlowItem from "../../v3/item/IsValidObjectIdFlowItem"
5
5
 
6
6
  class BuildAndQueriesFlowItem {
7
7
  execute(filters: any, model: mongoose.Model<any>) {
@@ -7,7 +7,7 @@ class BuildConditionFlowItem {
7
7
  exec(key: string, value: any, model: mongoose.Model<any>) {
8
8
  let condition = {} as any
9
9
  if (key.endsWith('DateRange')) {
10
- var fieldName = key.replace('Range', '')
10
+ var fieldName = this.replaceLast(key, 'Range', '')
11
11
  var values = value as any
12
12
  if (values[0]) {
13
13
  var momentValue = moment(values[0])
@@ -31,7 +31,7 @@ class BuildConditionFlowItem {
31
31
  }
32
32
  }
33
33
  } else if (key.endsWith('DateTimeRange')) {
34
- var fieldName = key.replace('Range', '')
34
+ var fieldName = this.replaceLast(key, 'Range', '')
35
35
  var values = value as any
36
36
  if (values[0]) {
37
37
  var momentValue = moment(values[0])
@@ -49,7 +49,7 @@ class BuildConditionFlowItem {
49
49
  }
50
50
  }
51
51
  } else if (key.endsWith('Range')) {
52
- var fieldName = key.replace('Range', '')
52
+ var fieldName = this.replaceLast(key, 'Range', '')
53
53
  var values = value as any
54
54
  if (values[0]) {
55
55
  condition[fieldName] = {
@@ -65,27 +65,37 @@ class BuildConditionFlowItem {
65
65
  }
66
66
  }
67
67
  } else if (key.endsWith('Like')) {
68
- var fieldName = key.replace('Like', '')
68
+ var fieldName = this.replaceLast(key, 'Like', '')
69
69
  condition[fieldName] = BuildRegexFlowItem.exec(value as string) //{ $regex: value as any, $options: 'i' }
70
70
  } else if (key.endsWith("AtLeastOneExists")) {
71
- key = key.replace("AtLeastOneExists", "");
71
+ key = this.replaceLast(key, "AtLeastOneExists", "");
72
72
 
73
73
  const fields = key.split('.')
74
74
  if (!fields) return condition;
75
75
 
76
76
  condition[fields[0]] = { $elemMatch: { [fields[1]]: { $exists: value as boolean } } }
77
77
  } else if (key.endsWith('Exists')) {
78
- var fieldName = key.replace('Exists', '')
78
+ var fieldName = this.replaceLast(key, 'Exists', '')
79
79
  condition[fieldName] = { $exists: value as boolean }
80
80
  } else if (key.endsWith("IsEmpty")) {
81
- key = key.replace("IsEmpty", "");
81
+ key = this.replaceLast(key, "IsEmpty", "");
82
82
  condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
83
+ } else if (key.endsWith("Minimum")) {
84
+ key = this.replaceLast(key, "Minimum", "");
85
+ condition[key] = {
86
+ $gte: Number(value)
87
+ };
88
+ } else if (key.endsWith("Maximum")) {
89
+ key = this.replaceLast(key, "Maximum", "");
90
+ condition[key] = {
91
+ $lte: Number(value)
92
+ };
83
93
  } else if (key.endsWith("NotIn")) {
84
- key = key.replace("NotIn", "");
94
+ key = this.replaceLast(key, "NotIn", "");
85
95
  var valuesArr = value?.trim().split(',').map((v: string) => v.trim());
86
96
  condition[key] = { $nin: valuesArr };
87
97
  } else if (key.endsWith("In")) {
88
- key = key.replace("In", "");
98
+ key = this.replaceLast(key, "In", "");
89
99
  var valuesArr = value?.trim().split(',').map((v: string) => v.trim());
90
100
  condition[key] = { $in: valuesArr };
91
101
  } else {
@@ -101,7 +111,7 @@ class BuildConditionFlowItem {
101
111
  })
102
112
 
103
113
  if (key.endsWith("NotIn")) {
104
- key = key.replace("NotIn", "");
114
+ key = this.replaceLast(key, "NotIn", "");
105
115
  condition[key] = { $nin: value };
106
116
  } else {
107
117
  condition[key] = { $in: value };
@@ -116,7 +126,7 @@ class BuildConditionFlowItem {
116
126
  arr.push(val);
117
127
  }
118
128
  if (key.endsWith("NotIn")) {
119
- key = key.replace("NotIn", "");
129
+ key = this.replaceLast(key, "NotIn", "");
120
130
  condition[key] = { $nin: arr };
121
131
  } else {
122
132
  condition[key] = { $in: arr };
@@ -129,6 +139,17 @@ class BuildConditionFlowItem {
129
139
  return condition
130
140
 
131
141
  }
142
+
143
+
144
+ replaceLast(str: string, target: string, replacement: string): string {
145
+ const index = str.lastIndexOf(target);
146
+
147
+ if (index === -1) return str;
148
+
149
+ return str.substring(0, index) +
150
+ replacement +
151
+ str.substring(index + target.length);
152
+ }
132
153
  }
133
154
 
134
155
  export default new BuildConditionFlowItem