c2-mongoose 2.1.261 → 2.1.265
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.
- package/dist/flow/SearcherFlow.js +32 -14
- package/package.json +2 -2
- package/src/flow/SearcherFlow.ts +34 -16
|
@@ -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,
|
|
92
|
-
return __generator(this, function (
|
|
93
|
-
switch (
|
|
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 (
|
|
152
|
-
metadata = stagesMetadata_1[
|
|
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 =
|
|
166
|
+
result = _d.sent();
|
|
167
167
|
if (!(0, Utils_1.isNotEmpty)(this.populate)) return [3 /*break*/, 3];
|
|
168
|
-
|
|
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
|
-
|
|
172
|
-
|
|
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,24 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
279
280
|
filters.$and.push(condition);
|
|
280
281
|
}
|
|
281
282
|
else {
|
|
282
|
-
if (
|
|
283
|
-
|
|
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
|
+
value === null || value === void 0 ? void 0 : value.forEach(function (v) {
|
|
288
|
+
if (typeof v === 'string' && _this.isValidObjectId(v)) {
|
|
289
|
+
v = new mongoose_1.Types.ObjectId(v);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
if (key.startsWith("notIn")) {
|
|
293
|
+
key = key.replace("notIn", "");
|
|
294
|
+
condition[key] = { $nin: value };
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
condition[key] = { $in: value };
|
|
298
|
+
}
|
|
284
299
|
}
|
|
285
|
-
else {
|
|
300
|
+
else if (Array.isArray(value)) {
|
|
286
301
|
var arr = [];
|
|
287
302
|
for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
|
|
288
303
|
var val = value_1[_i];
|
|
@@ -299,6 +314,9 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
299
314
|
condition[key] = { $in: arr };
|
|
300
315
|
}
|
|
301
316
|
}
|
|
317
|
+
else {
|
|
318
|
+
condition[key] = value;
|
|
319
|
+
}
|
|
302
320
|
filters.$and.push(condition);
|
|
303
321
|
}
|
|
304
322
|
}
|
|
@@ -306,8 +324,8 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
306
324
|
if ((0, Utils_1.isNotEmpty)(this.searchText) && (0, Utils_1.isNotEmpty)(camposString)) {
|
|
307
325
|
var regex = this.buildRegex(this.searchText);
|
|
308
326
|
var conditions = { $or: [] };
|
|
309
|
-
for (var
|
|
310
|
-
var fieldString = camposString_1[
|
|
327
|
+
for (var _a = 0, camposString_1 = camposString; _a < camposString_1.length; _a++) {
|
|
328
|
+
var fieldString = camposString_1[_a];
|
|
311
329
|
var conditionAux = {};
|
|
312
330
|
conditionAux[fieldString] = { $regex: regex };
|
|
313
331
|
conditions.$or.push(conditionAux);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c2-mongoose",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.265",
|
|
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
|
},
|
package/src/flow/SearcherFlow.ts
CHANGED
|
@@ -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,42 @@ class SearcherFlow<D> {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
else {
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
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
|
|
|
259
|
+
(value as [])?.forEach((v: any) => {
|
|
260
|
+
if (typeof v === 'string' && this.isValidObjectId(v)) {
|
|
261
|
+
v = new Types.ObjectId(v);
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
|
|
265
265
|
if (key.startsWith("notIn")) {
|
|
266
|
-
key = key.replace("notIn", "")
|
|
267
|
-
condition[key] = { $nin:
|
|
268
|
-
} else {
|
|
269
|
-
condition[key] = { $in: arr }
|
|
266
|
+
key = key.replace("notIn", "");
|
|
267
|
+
condition[key] = { $nin: value };
|
|
270
268
|
}
|
|
271
|
-
|
|
269
|
+
else {
|
|
270
|
+
condition[key] = { $in: value };
|
|
271
|
+
}
|
|
272
|
+
} else if (Array.isArray(value)) {
|
|
273
|
+
var arr = [];
|
|
274
|
+
for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
|
|
275
|
+
var val = value_1[_i];
|
|
276
|
+
if (typeof val === 'string' && this.isValidObjectId(val)) {
|
|
277
|
+
val = new Types.ObjectId(val);
|
|
278
|
+
}
|
|
279
|
+
arr.push(val);
|
|
280
|
+
}
|
|
281
|
+
if (key.startsWith("notIn")) {
|
|
282
|
+
key = key.replace("notIn", "");
|
|
283
|
+
condition[key] = { $nin: arr };
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
condition[key] = { $in: arr };
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
condition[key] = value;
|
|
272
290
|
}
|
|
273
291
|
filters.$and.push(condition)
|
|
274
292
|
}
|