c2-mongoose 2.1.57 → 2.1.59
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 +8 -2
- package/dist/flow/SearchFlow.js +17 -8
- package/package.json +1 -1
- package/src/flow/SearchFlow.ts +20 -10
|
@@ -6,18 +6,24 @@ 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
|
+
};
|
|
14
17
|
constructor(params: any);
|
|
15
18
|
buildPopulate(): any;
|
|
19
|
+
buildProjections(): {
|
|
20
|
+
[key: string]: number;
|
|
21
|
+
};
|
|
16
22
|
buildPath(target: string, nested?: string): any;
|
|
17
23
|
buildOrdenation(): any;
|
|
18
24
|
buildRegex(searchText: string): RegExp;
|
|
19
25
|
searchPageable(model: mongoose.Model<any>, options: SearchOptions): Promise<{
|
|
20
|
-
items: any
|
|
26
|
+
items: any;
|
|
21
27
|
paging: any;
|
|
22
28
|
}>;
|
|
23
29
|
search(model: mongoose.Model<any>, options?: SearchOptions): Promise<SearchResponse<any>>;
|
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 {};
|
|
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 = {};
|
|
@@ -148,7 +160,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
148
160
|
SearchFlow.prototype.searchPageable = function (model, options) {
|
|
149
161
|
var _a;
|
|
150
162
|
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
-
var stagesItems, result
|
|
163
|
+
var stagesItems, result;
|
|
152
164
|
return __generator(this, function (_b) {
|
|
153
165
|
switch (_b.label) {
|
|
154
166
|
case 0:
|
|
@@ -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
|
{
|
|
@@ -177,12 +190,8 @@ var SearchFlow = /** @class */ (function () {
|
|
|
177
190
|
]).session(options === null || options === void 0 ? void 0 : options.session)];
|
|
178
191
|
case 1:
|
|
179
192
|
result = _b.sent();
|
|
180
|
-
populate = __assign(__assign({}, this.populate), { select: this.select });
|
|
181
|
-
return [4 /*yield*/, model.populate(result[0].items, populate)];
|
|
182
|
-
case 2:
|
|
183
|
-
items = _b.sent();
|
|
184
193
|
return [2 /*return*/, {
|
|
185
|
-
items: items,
|
|
194
|
+
items: result[0].items,
|
|
186
195
|
paging: ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.paging[0]) || { total: 0, page: 1, limit: this.limit }
|
|
187
196
|
}];
|
|
188
197
|
}
|
|
@@ -361,7 +370,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
361
370
|
var key = _a[0], value = _a[1];
|
|
362
371
|
if ((0, Utils_1.isNotEmpty)(value)) {
|
|
363
372
|
var condition = {};
|
|
364
|
-
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)) {
|
|
365
374
|
return;
|
|
366
375
|
}
|
|
367
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 }
|
|
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 {}
|
|
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
|
|
|
@@ -103,14 +119,8 @@ abstract class SearchFlow {
|
|
|
103
119
|
}
|
|
104
120
|
]
|
|
105
121
|
).session(options?.session as ClientSession)
|
|
106
|
-
let populate = {
|
|
107
|
-
...this.populate,
|
|
108
|
-
select: this.select
|
|
109
|
-
}
|
|
110
|
-
let items = await model.populate(result[0].items, populate)
|
|
111
|
-
|
|
112
122
|
return {
|
|
113
|
-
items: items,
|
|
123
|
+
items: result[0].items,
|
|
114
124
|
paging: result[0]?.paging[0] || { total: 0, page: 1, limit: this.limit }
|
|
115
125
|
}
|
|
116
126
|
}
|
|
@@ -260,7 +270,7 @@ abstract class SearchFlow {
|
|
|
260
270
|
Object.entries(objectSearch.model).forEach(([key, value]) => {
|
|
261
271
|
if (isNotEmpty(value)) {
|
|
262
272
|
let condition = {} as any
|
|
263
|
-
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)) {
|
|
264
274
|
return
|
|
265
275
|
}
|
|
266
276
|
|