c2-mongoose 2.1.93 → 2.1.95
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 +21 -30
- package/package.json +1 -1
- package/src/flow/SearchFlow.ts +38 -22
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -46,15 +46,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
-
if (ar || !(i in from)) {
|
|
52
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
-
ar[i] = from[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
-
};
|
|
58
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
51
|
};
|
|
@@ -191,34 +182,34 @@ var SearchFlow = /** @class */ (function () {
|
|
|
191
182
|
SearchFlow.prototype.searchPageable = function (model, options) {
|
|
192
183
|
var _a;
|
|
193
184
|
return __awaiter(this, void 0, void 0, function () {
|
|
194
|
-
var stagesItems, result, items, _i, _b, populate;
|
|
185
|
+
var stagesItems, stagesPaging, result, items, _i, _b, populate;
|
|
195
186
|
return __generator(this, function (_c) {
|
|
196
187
|
switch (_c.label) {
|
|
197
188
|
case 0:
|
|
198
|
-
stagesItems =
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
{ $
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
189
|
+
stagesItems = [{ $match: this.filters }];
|
|
190
|
+
if ((0, Utils_1.isNotEmpty)(options.unions)) {
|
|
191
|
+
stagesItems.push.apply(stagesItems, options.unions);
|
|
192
|
+
}
|
|
193
|
+
if ((0, Utils_1.isNotEmpty)(this.projection)) {
|
|
194
|
+
stagesItems.push({ $project: this.projection });
|
|
195
|
+
}
|
|
196
|
+
if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
|
|
197
|
+
stagesItems.push.apply(stagesItems, options.pipelines);
|
|
198
|
+
}
|
|
199
|
+
stagesItems.push({ $sort: this.sort });
|
|
200
|
+
stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 });
|
|
201
|
+
stagesItems.push({ $limit: this.limit });
|
|
202
|
+
stagesPaging = [{ $match: this.filters }];
|
|
203
|
+
if ((0, Utils_1.isNotEmpty)(options.unions)) {
|
|
204
|
+
stagesPaging.push.apply(stagesPaging, options.unions);
|
|
205
|
+
}
|
|
206
|
+
stagesPaging.push({ $count: "total" });
|
|
207
|
+
stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } });
|
|
207
208
|
return [4 /*yield*/, model.aggregate([
|
|
208
209
|
{
|
|
209
210
|
$facet: {
|
|
210
211
|
items: stagesItems,
|
|
211
|
-
paging:
|
|
212
|
-
{ $match: this.filters },
|
|
213
|
-
(0, Utils_1.isNotEmpty)(options.unions) ? __spreadArray([], options.unions, true) : undefined,
|
|
214
|
-
{ $count: "total" },
|
|
215
|
-
{
|
|
216
|
-
$addFields: {
|
|
217
|
-
page: this.page || 1,
|
|
218
|
-
limit: this.limit
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
]
|
|
212
|
+
paging: stagesPaging
|
|
222
213
|
}
|
|
223
214
|
}
|
|
224
215
|
]).session(options === null || options === void 0 ? void 0 : options.session)];
|
package/package.json
CHANGED
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -118,33 +118,49 @@ abstract class SearchFlow {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
async searchPageable(model: mongoose.Model<any>, options: SearchOptions) {
|
|
121
|
-
let stagesItems = [
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
]
|
|
121
|
+
// let stagesItems = [
|
|
122
|
+
// { $match: this.filters },
|
|
123
|
+
// isNotEmpty(options.unions) ? options.unions : undefined,
|
|
124
|
+
// this.projection ? { $project: this.projection } : { $addFields: {} },
|
|
125
|
+
// ...options.pipelines,
|
|
126
|
+
// { $sort: this.sort },
|
|
127
|
+
// { $skip: ((this.page - 1) * this.limit) || 0 },
|
|
128
|
+
// { $limit: this.limit },
|
|
129
|
+
// ]
|
|
130
|
+
|
|
131
|
+
let stagesItems: any[] = [{ $match: this.filters }]
|
|
132
|
+
|
|
133
|
+
if (isNotEmpty(options.unions)) {
|
|
134
|
+
stagesItems.push(...options.unions)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (isNotEmpty(this.projection)) {
|
|
138
|
+
stagesItems.push({ $project: this.projection })
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (isNotEmpty(options.pipelines)) {
|
|
142
|
+
stagesItems.push(...options.pipelines)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
stagesItems.push({ $sort: this.sort })
|
|
146
|
+
stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 })
|
|
147
|
+
stagesItems.push({ $limit: this.limit })
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
let stagesPaging: any[] = [{ $match: this.filters }]
|
|
151
|
+
if (isNotEmpty(options.unions)) {
|
|
152
|
+
stagesPaging.push(...options.unions)
|
|
153
|
+
}
|
|
154
|
+
stagesPaging.push({ $count: "total" })
|
|
155
|
+
stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } })
|
|
156
|
+
|
|
130
157
|
|
|
131
158
|
const result = await model.aggregate(
|
|
132
159
|
[
|
|
133
160
|
{
|
|
134
161
|
$facet: {
|
|
135
|
-
items: stagesItems
|
|
136
|
-
paging:
|
|
137
|
-
{ $match: this.filters },
|
|
138
|
-
isNotEmpty(options.unions) ? [...options.unions] as any : undefined,
|
|
139
|
-
{ $count: "total" },
|
|
140
|
-
{
|
|
141
|
-
$addFields:
|
|
142
|
-
{
|
|
143
|
-
page: this.page || 1,
|
|
144
|
-
limit: this.limit
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
]
|
|
162
|
+
items: stagesItems,
|
|
163
|
+
paging: stagesPaging
|
|
148
164
|
}
|
|
149
165
|
}
|
|
150
166
|
]
|