c2-mongoose 2.1.23 → 2.1.25
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.js +10 -6
- package/package.json +1 -1
- package/src/flow/SearchFlow.ts +12 -9
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -56,7 +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.pageable = true;
|
|
60
59
|
this.searchPageable = function (model) { return __awaiter(_this, void 0, void 0, function () {
|
|
61
60
|
var sort, items;
|
|
62
61
|
return __generator(this, function (_a) {
|
|
@@ -85,6 +84,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
85
84
|
this.populate = params.populate;
|
|
86
85
|
this.page = Number(params.page || undefined);
|
|
87
86
|
this.limit = Number(params.limit || 25);
|
|
87
|
+
this.pageable = params.pageable == undefined ? true : params.pageable;
|
|
88
88
|
this.buildPopulate();
|
|
89
89
|
}
|
|
90
90
|
SearchFlow.prototype.buildPopulate = function () {
|
|
@@ -153,6 +153,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
153
153
|
.find(this.filters, this.select)
|
|
154
154
|
.populate(this.populate)
|
|
155
155
|
.sort(sort)
|
|
156
|
+
.limit(this.limit)
|
|
156
157
|
.collation({
|
|
157
158
|
locale: Environment_1.dbCollation || "pt"
|
|
158
159
|
})];
|
|
@@ -165,20 +166,23 @@ var SearchFlow = /** @class */ (function () {
|
|
|
165
166
|
};
|
|
166
167
|
SearchFlow.prototype.result = function (model, items) {
|
|
167
168
|
return __awaiter(this, void 0, void 0, function () {
|
|
168
|
-
var total, paging
|
|
169
|
+
var searchResponse, total, paging;
|
|
169
170
|
return __generator(this, function (_a) {
|
|
170
171
|
switch (_a.label) {
|
|
171
|
-
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)];
|
|
172
177
|
case 1:
|
|
173
178
|
total = _a.sent();
|
|
174
179
|
paging = {};
|
|
175
180
|
paging.total = total;
|
|
176
181
|
paging.page = Number(this.page);
|
|
177
182
|
paging.limit = Number(this.limit);
|
|
178
|
-
searchResponse = {};
|
|
179
|
-
searchResponse.items = items;
|
|
180
183
|
searchResponse.paging = paging;
|
|
181
|
-
|
|
184
|
+
_a.label = 2;
|
|
185
|
+
case 2: return [2 /*return*/, searchResponse];
|
|
182
186
|
}
|
|
183
187
|
});
|
|
184
188
|
});
|
package/package.json
CHANGED
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -13,7 +13,7 @@ abstract class SearchFlow {
|
|
|
13
13
|
select: string
|
|
14
14
|
populate: any
|
|
15
15
|
filters: any
|
|
16
|
-
pageable: boolean
|
|
16
|
+
pageable: boolean
|
|
17
17
|
|
|
18
18
|
constructor(params: any) {
|
|
19
19
|
this.searchText = params.searchText || ""
|
|
@@ -23,6 +23,7 @@ abstract class SearchFlow {
|
|
|
23
23
|
this.populate = params.populate
|
|
24
24
|
this.page = Number(params.page || undefined)
|
|
25
25
|
this.limit = Number(params.limit || 25)
|
|
26
|
+
this.pageable = params.pageable == undefined ? true : params.pageable
|
|
26
27
|
this.buildPopulate()
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -99,6 +100,7 @@ abstract class SearchFlow {
|
|
|
99
100
|
.find(this.filters, this.select)
|
|
100
101
|
.populate(this.populate)
|
|
101
102
|
.sort(sort)
|
|
103
|
+
.limit(this.limit)
|
|
102
104
|
.collation({
|
|
103
105
|
locale: dbCollation || "pt"
|
|
104
106
|
}) as []
|
|
@@ -107,16 +109,17 @@ abstract class SearchFlow {
|
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
private async result(model: mongoose.Model<any>, items: []): Promise<SearchResponse<any>> {
|
|
110
|
-
var total = await this.count(model)
|
|
111
|
-
|
|
112
|
-
var paging: Pagination = {}
|
|
113
|
-
paging.total = total
|
|
114
|
-
paging.page = Number(this.page)
|
|
115
|
-
paging.limit = Number(this.limit)
|
|
116
|
-
|
|
117
112
|
var searchResponse: SearchResponse<any> = {}
|
|
118
113
|
searchResponse.items = items
|
|
119
|
-
|
|
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
|
+
}
|
|
120
123
|
|
|
121
124
|
return searchResponse
|
|
122
125
|
}
|