c2-mongoose 2.1.22 → 2.1.24
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 +1 -1
- package/dist/flow/SearchFlow.js +11 -15
- package/package.json +1 -1
- package/src/flow/SearchFlow.ts +13 -21
|
@@ -9,11 +9,11 @@ declare abstract class SearchFlow {
|
|
|
9
9
|
select: string;
|
|
10
10
|
populate: any;
|
|
11
11
|
filters: any;
|
|
12
|
+
pageable: boolean;
|
|
12
13
|
constructor(params: any);
|
|
13
14
|
buildPopulate(): any;
|
|
14
15
|
buildPath(target: string, nested?: string): any;
|
|
15
16
|
buildOrdenation(): any;
|
|
16
|
-
private isPageable;
|
|
17
17
|
diacriticSensitiveRegex(string?: string): string;
|
|
18
18
|
search(model: mongoose.Model<any>): Promise<SearchResponse<any>>;
|
|
19
19
|
private searchPageable;
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -56,15 +56,6 @@ var Utils_1 = require("../utils/Utils");
|
|
|
56
56
|
var SearchFlow = /** @class */ (function () {
|
|
57
57
|
function SearchFlow(params) {
|
|
58
58
|
var _this = this;
|
|
59
|
-
this.isPageable = function () {
|
|
60
|
-
if ((0, Utils_1.isEmpty)(_this.page)) {
|
|
61
|
-
_this.page = 1;
|
|
62
|
-
}
|
|
63
|
-
if (_this.page >= 0) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
};
|
|
68
59
|
this.searchPageable = function (model) { return __awaiter(_this, void 0, void 0, function () {
|
|
69
60
|
var sort, items;
|
|
70
61
|
return __generator(this, function (_a) {
|
|
@@ -93,6 +84,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
93
84
|
this.populate = params.populate;
|
|
94
85
|
this.page = Number(params.page || undefined);
|
|
95
86
|
this.limit = Number(params.limit || 25);
|
|
87
|
+
this.pageable = params.pageable || true;
|
|
96
88
|
this.buildPopulate();
|
|
97
89
|
}
|
|
98
90
|
SearchFlow.prototype.buildPopulate = function () {
|
|
@@ -141,7 +133,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
141
133
|
return __generator(this, function (_a) {
|
|
142
134
|
switch (_a.label) {
|
|
143
135
|
case 0:
|
|
144
|
-
if (!this.
|
|
136
|
+
if (!this.pageable) return [3 /*break*/, 2];
|
|
145
137
|
return [4 /*yield*/, this.searchPageable(model)];
|
|
146
138
|
case 1: return [2 /*return*/, _a.sent()];
|
|
147
139
|
case 2: return [4 /*yield*/, this.searchNoPageable(model)];
|
|
@@ -161,6 +153,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
161
153
|
.find(this.filters, this.select)
|
|
162
154
|
.populate(this.populate)
|
|
163
155
|
.sort(sort)
|
|
156
|
+
.limit(this.limit)
|
|
164
157
|
.collation({
|
|
165
158
|
locale: Environment_1.dbCollation || "pt"
|
|
166
159
|
})];
|
|
@@ -173,20 +166,23 @@ var SearchFlow = /** @class */ (function () {
|
|
|
173
166
|
};
|
|
174
167
|
SearchFlow.prototype.result = function (model, items) {
|
|
175
168
|
return __awaiter(this, void 0, void 0, function () {
|
|
176
|
-
var total, paging
|
|
169
|
+
var searchResponse, total, paging;
|
|
177
170
|
return __generator(this, function (_a) {
|
|
178
171
|
switch (_a.label) {
|
|
179
|
-
case 0:
|
|
172
|
+
case 0:
|
|
173
|
+
searchResponse = {};
|
|
174
|
+
searchResponse.items = items;
|
|
175
|
+
if (!this.pageable) return [3 /*break*/, 2];
|
|
176
|
+
return [4 /*yield*/, this.count(model)];
|
|
180
177
|
case 1:
|
|
181
178
|
total = _a.sent();
|
|
182
179
|
paging = {};
|
|
183
180
|
paging.total = total;
|
|
184
181
|
paging.page = Number(this.page);
|
|
185
182
|
paging.limit = Number(this.limit);
|
|
186
|
-
searchResponse = {};
|
|
187
|
-
searchResponse.items = items;
|
|
188
183
|
searchResponse.paging = paging;
|
|
189
|
-
|
|
184
|
+
_a.label = 2;
|
|
185
|
+
case 2: return [2 /*return*/, searchResponse];
|
|
190
186
|
}
|
|
191
187
|
});
|
|
192
188
|
});
|
package/package.json
CHANGED
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -13,6 +13,7 @@ abstract class SearchFlow {
|
|
|
13
13
|
select: string
|
|
14
14
|
populate: any
|
|
15
15
|
filters: any
|
|
16
|
+
pageable: boolean
|
|
16
17
|
|
|
17
18
|
constructor(params: any) {
|
|
18
19
|
this.searchText = params.searchText || ""
|
|
@@ -22,6 +23,7 @@ abstract class SearchFlow {
|
|
|
22
23
|
this.populate = params.populate
|
|
23
24
|
this.page = Number(params.page || undefined)
|
|
24
25
|
this.limit = Number(params.limit || 25)
|
|
26
|
+
this.pageable = params.pageable || true
|
|
25
27
|
this.buildPopulate()
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -59,18 +61,6 @@ abstract class SearchFlow {
|
|
|
59
61
|
return order
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
private isPageable = () => {
|
|
63
|
-
if (isEmpty(this.page)) {
|
|
64
|
-
this.page = 1
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (this.page >= 0) {
|
|
68
|
-
return true
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return false
|
|
72
|
-
}
|
|
73
|
-
|
|
74
64
|
public diacriticSensitiveRegex(string: string = ""): string {
|
|
75
65
|
return string
|
|
76
66
|
.replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
|
|
@@ -82,7 +72,7 @@ abstract class SearchFlow {
|
|
|
82
72
|
}
|
|
83
73
|
|
|
84
74
|
public async search(model: mongoose.Model<any>): Promise<SearchResponse<any>> {
|
|
85
|
-
if (this.
|
|
75
|
+
if (this.pageable) {
|
|
86
76
|
return await this.searchPageable(model)
|
|
87
77
|
}
|
|
88
78
|
|
|
@@ -110,6 +100,7 @@ abstract class SearchFlow {
|
|
|
110
100
|
.find(this.filters, this.select)
|
|
111
101
|
.populate(this.populate)
|
|
112
102
|
.sort(sort)
|
|
103
|
+
.limit(this.limit)
|
|
113
104
|
.collation({
|
|
114
105
|
locale: dbCollation || "pt"
|
|
115
106
|
}) as []
|
|
@@ -118,16 +109,17 @@ abstract class SearchFlow {
|
|
|
118
109
|
}
|
|
119
110
|
|
|
120
111
|
private async result(model: mongoose.Model<any>, items: []): Promise<SearchResponse<any>> {
|
|
121
|
-
var total = await this.count(model)
|
|
122
|
-
|
|
123
|
-
var paging: Pagination = {}
|
|
124
|
-
paging.total = total
|
|
125
|
-
paging.page = Number(this.page)
|
|
126
|
-
paging.limit = Number(this.limit)
|
|
127
|
-
|
|
128
112
|
var searchResponse: SearchResponse<any> = {}
|
|
129
113
|
searchResponse.items = items
|
|
130
|
-
|
|
114
|
+
|
|
115
|
+
if (this.pageable) {
|
|
116
|
+
var total = await this.count(model)
|
|
117
|
+
var paging: Pagination = {}
|
|
118
|
+
paging.total = total
|
|
119
|
+
paging.page = Number(this.page)
|
|
120
|
+
paging.limit = Number(this.limit)
|
|
121
|
+
searchResponse.paging = paging
|
|
122
|
+
}
|
|
131
123
|
|
|
132
124
|
return searchResponse
|
|
133
125
|
}
|