c2-mongoose 2.1.304 → 2.1.306
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.
|
@@ -18,6 +18,9 @@ declare class SearcherFlow<D> {
|
|
|
18
18
|
searchTextFields: string[];
|
|
19
19
|
orderSense: string;
|
|
20
20
|
orderBy: string;
|
|
21
|
+
groupBy: string[];
|
|
22
|
+
sumFields: string[];
|
|
23
|
+
groupFields: string[];
|
|
21
24
|
page: number;
|
|
22
25
|
limit: number;
|
|
23
26
|
pageable: boolean;
|
|
@@ -35,5 +38,6 @@ declare class SearcherFlow<D> {
|
|
|
35
38
|
isValidObjectId(value: string): boolean;
|
|
36
39
|
buildOrdenation(): any;
|
|
37
40
|
buildRegex(searchText: string): RegExp;
|
|
41
|
+
buildGrouping(fieldsToGroup: string[], sumFields: string[], countFields: string[]): void;
|
|
38
42
|
}
|
|
39
43
|
export default SearcherFlow;
|
|
@@ -70,6 +70,9 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
70
70
|
this.searchTextFields = [];
|
|
71
71
|
this.orderSense = "desc";
|
|
72
72
|
this.orderBy = "_id";
|
|
73
|
+
this.groupBy = [];
|
|
74
|
+
this.sumFields = [];
|
|
75
|
+
this.groupFields = [];
|
|
73
76
|
this.page = 1;
|
|
74
77
|
this.limit = 50;
|
|
75
78
|
this.pageable = true;
|
|
@@ -108,9 +111,6 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
108
111
|
}
|
|
109
112
|
stagesItems.push({ $sort: this.buildOrdenation() });
|
|
110
113
|
stagesPaging = [];
|
|
111
|
-
// if (isNotEmpty(options.pipelines)) {
|
|
112
|
-
// stagesPaging.push(...options.pipelines)
|
|
113
|
-
// }
|
|
114
114
|
if ((0, Utils_1.isNotEmpty)(options.unions)) {
|
|
115
115
|
stagesPaging.push.apply(stagesPaging, options.unions);
|
|
116
116
|
}
|
|
@@ -261,7 +261,7 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
261
261
|
}
|
|
262
262
|
else if (key.endsWith("IsEmpty")) {
|
|
263
263
|
key = key.replace("IsEmpty", "");
|
|
264
|
-
condition[key] = { $size:
|
|
264
|
+
condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
|
|
265
265
|
}
|
|
266
266
|
else {
|
|
267
267
|
if (((_c = (_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a.schema) === null || _b === void 0 ? void 0 : _b.paths[key]) === null || _c === void 0 ? void 0 : _c.instance) === 'Array') {
|
|
@@ -329,6 +329,9 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
329
329
|
'pageable',
|
|
330
330
|
'orderSense',
|
|
331
331
|
'orderBy',
|
|
332
|
+
'groupBy',
|
|
333
|
+
'sumFields',
|
|
334
|
+
'countFields',
|
|
332
335
|
'properties',
|
|
333
336
|
'populate',
|
|
334
337
|
'page',
|
|
@@ -449,6 +452,21 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
449
452
|
.replace(/[u|ü|ú|ù|U|Ú|Ü|Ù]/g, '[u,ü,ú,ù,U,Ú,Ü,Ù]');
|
|
450
453
|
return new RegExp("".concat(regexExpression), 'i');
|
|
451
454
|
};
|
|
455
|
+
SearcherFlow.prototype.buildGrouping = function (fieldsToGroup, sumFields, countFields) {
|
|
456
|
+
var groupsClauses = [];
|
|
457
|
+
fieldsToGroup.forEach(function (fieldToGroup) {
|
|
458
|
+
var groupClause = {
|
|
459
|
+
_id: "$".concat(fieldToGroup)
|
|
460
|
+
};
|
|
461
|
+
sumFields.forEach(function (sumField) {
|
|
462
|
+
groupClause[sumField] = { $sum: { $ifNull: ["$".concat(sumField), 0] } };
|
|
463
|
+
});
|
|
464
|
+
countFields.forEach(function (countField) {
|
|
465
|
+
groupClause[countField] = { $sum: 1 };
|
|
466
|
+
});
|
|
467
|
+
groupsClauses.push(groupClause);
|
|
468
|
+
});
|
|
469
|
+
};
|
|
452
470
|
return SearcherFlow;
|
|
453
471
|
}());
|
|
454
472
|
exports.default = SearcherFlow;
|
package/package.json
CHANGED
package/src/flow/SearcherFlow.ts
CHANGED
|
@@ -27,6 +27,9 @@ class SearcherFlow<D> {
|
|
|
27
27
|
public searchTextFields: string[] = []
|
|
28
28
|
public orderSense: string = "desc"
|
|
29
29
|
public orderBy: string = "_id"
|
|
30
|
+
public groupBy: string[] = []
|
|
31
|
+
public sumFields: string[] = []
|
|
32
|
+
public groupFields: string[] = []
|
|
30
33
|
public page: number = 1
|
|
31
34
|
public limit: number = 50
|
|
32
35
|
public pageable: boolean = true
|
|
@@ -69,11 +72,7 @@ class SearcherFlow<D> {
|
|
|
69
72
|
}
|
|
70
73
|
stagesItems.push({ $sort: this.buildOrdenation() })
|
|
71
74
|
|
|
72
|
-
///
|
|
73
75
|
let stagesPaging: any[] = []
|
|
74
|
-
// if (isNotEmpty(options.pipelines)) {
|
|
75
|
-
// stagesPaging.push(...options.pipelines)
|
|
76
|
-
// }
|
|
77
76
|
if (isNotEmpty(options.unions)) {
|
|
78
77
|
stagesPaging.push(...options.unions)
|
|
79
78
|
}
|
|
@@ -238,7 +237,7 @@ class SearcherFlow<D> {
|
|
|
238
237
|
condition[fieldName] = { $exists: value as boolean }
|
|
239
238
|
} else if (key.endsWith("IsEmpty")) {
|
|
240
239
|
key = key.replace("IsEmpty", "");
|
|
241
|
-
condition[key] = { $size:
|
|
240
|
+
condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
|
|
242
241
|
} else {
|
|
243
242
|
if (this.model?.schema?.paths[key]?.instance === 'Array') {
|
|
244
243
|
if (!Array.isArray(value)) {
|
|
@@ -259,7 +258,7 @@ class SearcherFlow<D> {
|
|
|
259
258
|
condition[key] = { $nin: value };
|
|
260
259
|
} else if (key.endsWith("IsEmpty")) {
|
|
261
260
|
key = key.replace("IsEmpty", "");
|
|
262
|
-
condition[key] = value ?
|
|
261
|
+
condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
|
|
263
262
|
} else {
|
|
264
263
|
condition[key] = { $in: value };
|
|
265
264
|
}
|
|
@@ -305,6 +304,9 @@ class SearcherFlow<D> {
|
|
|
305
304
|
'pageable',
|
|
306
305
|
'orderSense',
|
|
307
306
|
'orderBy',
|
|
307
|
+
'groupBy',
|
|
308
|
+
'sumFields',
|
|
309
|
+
'countFields',
|
|
308
310
|
'properties',
|
|
309
311
|
'populate',
|
|
310
312
|
'page',
|
|
@@ -437,6 +439,27 @@ class SearcherFlow<D> {
|
|
|
437
439
|
.replace(/[u|ü|ú|ù|U|Ú|Ü|Ù]/g, '[u,ü,ú,ù,U,Ú,Ü,Ù]')
|
|
438
440
|
return new RegExp(`${regexExpression}`, 'i');
|
|
439
441
|
}
|
|
442
|
+
|
|
443
|
+
buildGrouping(fieldsToGroup: string[], sumFields: string[], countFields: string[]) {
|
|
444
|
+
const groupsClauses = []
|
|
445
|
+
|
|
446
|
+
fieldsToGroup.forEach((fieldToGroup: string) => {
|
|
447
|
+
|
|
448
|
+
const groupClause: any = {
|
|
449
|
+
_id: `$${fieldToGroup}`
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
sumFields.forEach((sumField: string) => {
|
|
453
|
+
groupClause[sumField] = { $sum: { $ifNull: [`$${sumField}`, 0] } }
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
countFields.forEach((countField: string) => {
|
|
457
|
+
groupClause[countField] = { $sum: 1 }
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
groupsClauses.push(groupClause)
|
|
461
|
+
})
|
|
462
|
+
}
|
|
440
463
|
}
|
|
441
464
|
|
|
442
465
|
export default SearcherFlow
|