c2-mongoose 2.1.466 → 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.
|
@@ -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 =
|
|
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 =
|
|
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 =
|
|
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,43 +66,43 @@ var BuildConditionFlowItem = /** @class */ (function () {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
else if (key.endsWith('Like')) {
|
|
69
|
-
var fieldName =
|
|
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 =
|
|
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 =
|
|
80
|
+
var fieldName = this.replaceLast(key, 'Exists', '');
|
|
81
81
|
condition[fieldName] = { $exists: value };
|
|
82
82
|
}
|
|
83
83
|
else if (key.endsWith("IsEmpty")) {
|
|
84
|
-
key =
|
|
84
|
+
key = this.replaceLast(key, "IsEmpty", "");
|
|
85
85
|
condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
|
|
86
86
|
}
|
|
87
87
|
else if (key.endsWith("Minimum")) {
|
|
88
|
-
key =
|
|
88
|
+
key = this.replaceLast(key, "Minimum", "");
|
|
89
89
|
condition[key] = {
|
|
90
90
|
$gte: Number(value)
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
else if (key.endsWith("Maximum")) {
|
|
94
|
-
key =
|
|
94
|
+
key = this.replaceLast(key, "Maximum", "");
|
|
95
95
|
condition[key] = {
|
|
96
96
|
$lte: Number(value)
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
else if (key.endsWith("NotIn")) {
|
|
100
|
-
key =
|
|
100
|
+
key = this.replaceLast(key, "NotIn", "");
|
|
101
101
|
var valuesArr = value === null || value === void 0 ? void 0 : value.trim().split(',').map(function (v) { return v.trim(); });
|
|
102
102
|
condition[key] = { $nin: valuesArr };
|
|
103
103
|
}
|
|
104
104
|
else if (key.endsWith("In")) {
|
|
105
|
-
key =
|
|
105
|
+
key = this.replaceLast(key, "In", "");
|
|
106
106
|
var valuesArr = value === null || value === void 0 ? void 0 : value.trim().split(',').map(function (v) { return v.trim(); });
|
|
107
107
|
condition[key] = { $in: valuesArr };
|
|
108
108
|
}
|
|
@@ -117,7 +117,7 @@ var BuildConditionFlowItem = /** @class */ (function () {
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
if (key.endsWith("NotIn")) {
|
|
120
|
-
key =
|
|
120
|
+
key = this.replaceLast(key, "NotIn", "");
|
|
121
121
|
condition[key] = { $nin: value };
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
@@ -134,7 +134,7 @@ var BuildConditionFlowItem = /** @class */ (function () {
|
|
|
134
134
|
arr.push(val);
|
|
135
135
|
}
|
|
136
136
|
if (key.endsWith("NotIn")) {
|
|
137
|
-
key =
|
|
137
|
+
key = this.replaceLast(key, "NotIn", "");
|
|
138
138
|
condition[key] = { $nin: arr };
|
|
139
139
|
}
|
|
140
140
|
else {
|
|
@@ -147,6 +147,14 @@ var BuildConditionFlowItem = /** @class */ (function () {
|
|
|
147
147
|
}
|
|
148
148
|
return condition;
|
|
149
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
|
+
};
|
|
150
158
|
return BuildConditionFlowItem;
|
|
151
159
|
}());
|
|
152
160
|
exports.default = new BuildConditionFlowItem;
|
package/package.json
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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 =
|
|
52
|
+
var fieldName = this.replaceLast(key, 'Range', '')
|
|
53
53
|
var values = value as any
|
|
54
54
|
if (values[0]) {
|
|
55
55
|
condition[fieldName] = {
|
|
@@ -65,37 +65,37 @@ class BuildConditionFlowItem {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
} else if (key.endsWith('Like')) {
|
|
68
|
-
var fieldName =
|
|
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 =
|
|
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 =
|
|
78
|
+
var fieldName = this.replaceLast(key, 'Exists', '')
|
|
79
79
|
condition[fieldName] = { $exists: value as boolean }
|
|
80
80
|
} else if (key.endsWith("IsEmpty")) {
|
|
81
|
-
key =
|
|
81
|
+
key = this.replaceLast(key, "IsEmpty", "");
|
|
82
82
|
condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
|
|
83
|
-
}
|
|
84
|
-
key =
|
|
83
|
+
} else if (key.endsWith("Minimum")) {
|
|
84
|
+
key = this.replaceLast(key, "Minimum", "");
|
|
85
85
|
condition[key] = {
|
|
86
86
|
$gte: Number(value)
|
|
87
87
|
};
|
|
88
88
|
} else if (key.endsWith("Maximum")) {
|
|
89
|
-
key =
|
|
89
|
+
key = this.replaceLast(key, "Maximum", "");
|
|
90
90
|
condition[key] = {
|
|
91
91
|
$lte: Number(value)
|
|
92
92
|
};
|
|
93
93
|
} else if (key.endsWith("NotIn")) {
|
|
94
|
-
key =
|
|
94
|
+
key = this.replaceLast(key, "NotIn", "");
|
|
95
95
|
var valuesArr = value?.trim().split(',').map((v: string) => v.trim());
|
|
96
96
|
condition[key] = { $nin: valuesArr };
|
|
97
97
|
} else if (key.endsWith("In")) {
|
|
98
|
-
key =
|
|
98
|
+
key = this.replaceLast(key, "In", "");
|
|
99
99
|
var valuesArr = value?.trim().split(',').map((v: string) => v.trim());
|
|
100
100
|
condition[key] = { $in: valuesArr };
|
|
101
101
|
} else {
|
|
@@ -111,7 +111,7 @@ class BuildConditionFlowItem {
|
|
|
111
111
|
})
|
|
112
112
|
|
|
113
113
|
if (key.endsWith("NotIn")) {
|
|
114
|
-
key =
|
|
114
|
+
key = this.replaceLast(key, "NotIn", "");
|
|
115
115
|
condition[key] = { $nin: value };
|
|
116
116
|
} else {
|
|
117
117
|
condition[key] = { $in: value };
|
|
@@ -126,7 +126,7 @@ class BuildConditionFlowItem {
|
|
|
126
126
|
arr.push(val);
|
|
127
127
|
}
|
|
128
128
|
if (key.endsWith("NotIn")) {
|
|
129
|
-
key =
|
|
129
|
+
key = this.replaceLast(key, "NotIn", "");
|
|
130
130
|
condition[key] = { $nin: arr };
|
|
131
131
|
} else {
|
|
132
132
|
condition[key] = { $in: arr };
|
|
@@ -139,6 +139,17 @@ class BuildConditionFlowItem {
|
|
|
139
139
|
return condition
|
|
140
140
|
|
|
141
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
|
+
}
|
|
142
153
|
}
|
|
143
154
|
|
|
144
155
|
export default new BuildConditionFlowItem
|