c2-mongoose 2.1.58 → 2.1.60
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/SearchFlow.d.ts +7 -1
- package/dist/flow/SearchFlow.js +15 -2
- package/package.json +1 -1
- package/src/flow/SearchFlow.ts +19 -3
|
@@ -6,13 +6,19 @@ declare abstract class SearchFlow {
|
|
|
6
6
|
orderBy: string;
|
|
7
7
|
page: number;
|
|
8
8
|
limit: number;
|
|
9
|
-
select: string;
|
|
9
|
+
select: string | string[];
|
|
10
10
|
populate: any;
|
|
11
11
|
filters: any;
|
|
12
12
|
sort: any;
|
|
13
13
|
pageable: boolean;
|
|
14
|
+
projection: {
|
|
15
|
+
[key: string]: number;
|
|
16
|
+
} | undefined;
|
|
14
17
|
constructor(params: any);
|
|
15
18
|
buildPopulate(): any;
|
|
19
|
+
buildProjections(): {
|
|
20
|
+
[key: string]: number;
|
|
21
|
+
} | undefined;
|
|
16
22
|
buildPath(target: string, nested?: string): any;
|
|
17
23
|
buildOrdenation(): any;
|
|
18
24
|
buildRegex(searchText: string): RegExp;
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -101,6 +101,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
101
101
|
this.page = Number(params.page || 1);
|
|
102
102
|
this.limit = Number(params.limit || 25);
|
|
103
103
|
this.pageable = params.pageable == false || params.pageable == 'false' ? false : true;
|
|
104
|
+
this.projection = this.buildProjections();
|
|
104
105
|
this.buildPopulate();
|
|
105
106
|
this.buildOrdenation();
|
|
106
107
|
}
|
|
@@ -118,6 +119,17 @@ var SearchFlow = /** @class */ (function () {
|
|
|
118
119
|
}
|
|
119
120
|
this.populate = populates;
|
|
120
121
|
};
|
|
122
|
+
SearchFlow.prototype.buildProjections = function () {
|
|
123
|
+
if (!Array.isArray(this.select)) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
var projection = {};
|
|
127
|
+
for (var _i = 0, _a = this.select; _i < _a.length; _i++) {
|
|
128
|
+
var field = _a[_i];
|
|
129
|
+
projection[field] = 1;
|
|
130
|
+
}
|
|
131
|
+
return projection;
|
|
132
|
+
};
|
|
121
133
|
SearchFlow.prototype.buildPath = function (target, nested) {
|
|
122
134
|
if (nested === void 0) { nested = ""; }
|
|
123
135
|
var populate = {};
|
|
@@ -156,7 +168,8 @@ var SearchFlow = /** @class */ (function () {
|
|
|
156
168
|
{ $match: this.filters },
|
|
157
169
|
{ $sort: this.sort },
|
|
158
170
|
{ $skip: (this.page - 1) * this.limit },
|
|
159
|
-
{ $limit: this.limit }
|
|
171
|
+
{ $limit: this.limit },
|
|
172
|
+
{ $project: this.projection }
|
|
160
173
|
], options.pipelines, true);
|
|
161
174
|
return [4 /*yield*/, model.aggregate([
|
|
162
175
|
{
|
|
@@ -357,7 +370,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
357
370
|
var key = _a[0], value = _a[1];
|
|
358
371
|
if ((0, Utils_1.isNotEmpty)(value)) {
|
|
359
372
|
var condition = {};
|
|
360
|
-
if (['pageable', 'order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
373
|
+
if (['projection', 'pageable', 'order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
361
374
|
return;
|
|
362
375
|
}
|
|
363
376
|
if (value === 'true') {
|
package/package.json
CHANGED
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import moment from "moment"
|
|
2
2
|
import mongoose, { ClientSession } from "mongoose"
|
|
3
3
|
import { dbCollation } from "../configuration/Environment"
|
|
4
|
-
import { Pagination,
|
|
4
|
+
import { Pagination, SearchOptions, SearchResponse } from "../types/SearchResponse"
|
|
5
5
|
import { isEmpty, isNotEmpty } from "../utils/Utils"
|
|
6
6
|
|
|
7
7
|
abstract class SearchFlow {
|
|
@@ -10,11 +10,12 @@ abstract class SearchFlow {
|
|
|
10
10
|
orderBy: string
|
|
11
11
|
page: number
|
|
12
12
|
limit: number
|
|
13
|
-
select: string
|
|
13
|
+
select: string | string[]
|
|
14
14
|
populate: any
|
|
15
15
|
filters: any
|
|
16
16
|
sort: any
|
|
17
17
|
pageable: boolean
|
|
18
|
+
projection: { [key: string]: number } | undefined
|
|
18
19
|
|
|
19
20
|
constructor(params: any) {
|
|
20
21
|
this.searchText = params.searchText || ""
|
|
@@ -25,6 +26,7 @@ abstract class SearchFlow {
|
|
|
25
26
|
this.page = Number(params.page || 1)
|
|
26
27
|
this.limit = Number(params.limit || 25)
|
|
27
28
|
this.pageable = params.pageable == false || params.pageable == 'false' ? false : true
|
|
29
|
+
this.projection = this.buildProjections()
|
|
28
30
|
this.buildPopulate()
|
|
29
31
|
this.buildOrdenation()
|
|
30
32
|
}
|
|
@@ -45,6 +47,19 @@ abstract class SearchFlow {
|
|
|
45
47
|
this.populate = populates
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
buildProjections() {
|
|
51
|
+
if (!Array.isArray(this.select)) {
|
|
52
|
+
return undefined
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let projection: { [key: string]: number } = {}
|
|
56
|
+
for (var field of this.select) {
|
|
57
|
+
projection[field] = 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return projection
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
public buildPath(target: string, nested: string = "") {
|
|
49
64
|
var populate = {} as any
|
|
50
65
|
populate.path = target
|
|
@@ -80,6 +95,7 @@ abstract class SearchFlow {
|
|
|
80
95
|
{ $sort: this.sort },
|
|
81
96
|
{ $skip: (this.page - 1) * this.limit },
|
|
82
97
|
{ $limit: this.limit },
|
|
98
|
+
{ $project: this.projection },
|
|
83
99
|
...options.pipelines
|
|
84
100
|
]
|
|
85
101
|
|
|
@@ -254,7 +270,7 @@ abstract class SearchFlow {
|
|
|
254
270
|
Object.entries(objectSearch.model).forEach(([key, value]) => {
|
|
255
271
|
if (isNotEmpty(value)) {
|
|
256
272
|
let condition = {} as any
|
|
257
|
-
if (['pageable', 'order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
273
|
+
if (['projection', 'pageable', 'order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
258
274
|
return
|
|
259
275
|
}
|
|
260
276
|
|