c2-mongoose 2.1.224 → 2.1.225
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 +2 -2
- package/dist/flow/SearchFlow.js +5 -7
- package/package.json +1 -1
- package/src/flow/SearchFlow.ts +34 -17
|
@@ -12,7 +12,7 @@ declare abstract class SearchFlow {
|
|
|
12
12
|
orderBy: string;
|
|
13
13
|
page: number;
|
|
14
14
|
limit: number;
|
|
15
|
-
select: string[];
|
|
15
|
+
select: string | string[];
|
|
16
16
|
populate: any;
|
|
17
17
|
filters: any;
|
|
18
18
|
sort: any;
|
|
@@ -20,7 +20,7 @@ declare abstract class SearchFlow {
|
|
|
20
20
|
onlyMetadata: boolean;
|
|
21
21
|
projection: {
|
|
22
22
|
[key: string]: number;
|
|
23
|
-
};
|
|
23
|
+
} | undefined;
|
|
24
24
|
constructor(params: any);
|
|
25
25
|
buildProjections(): any;
|
|
26
26
|
buildProjectionNested(projectCurrent: any, field: string, include: boolean): any;
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -51,11 +51,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
// import moment from "moment"
|
|
54
|
-
var moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
55
54
|
var mongoose_1 = require("mongoose");
|
|
56
55
|
var Utils_1 = require("../utils/Utils");
|
|
57
|
-
var
|
|
58
|
-
var BuildSelectSingleFlowItem_1 = __importDefault(require("./item/BuildSelectSingleFlowItem"));
|
|
56
|
+
var moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
59
57
|
var SearchFlow = /** @class */ (function () {
|
|
60
58
|
function SearchFlow(params) {
|
|
61
59
|
// Incluir as propriedades adicionais de 'params' como propriedades da classe
|
|
@@ -181,7 +179,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
181
179
|
}
|
|
182
180
|
stagesItems.push({ $match: this.filters });
|
|
183
181
|
if ((0, Utils_1.isNotEmpty)(this.projection)) {
|
|
184
|
-
stagesItems.push({ $project:
|
|
182
|
+
stagesItems.push({ $project: this.projection });
|
|
185
183
|
}
|
|
186
184
|
stagesItems.push({ $sort: this.sort });
|
|
187
185
|
stagesMetadata = [];
|
|
@@ -215,7 +213,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
215
213
|
if (!(_a < _b.length)) return [3 /*break*/, 5];
|
|
216
214
|
populate = _b[_a];
|
|
217
215
|
_c = result[0];
|
|
218
|
-
return [4 /*yield*/, model.populate(result[0].items,
|
|
216
|
+
return [4 /*yield*/, model.populate(result[0].items, populate)];
|
|
219
217
|
case 3:
|
|
220
218
|
_c.items = _d.sent();
|
|
221
219
|
_d.label = 4;
|
|
@@ -244,7 +242,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
244
242
|
}
|
|
245
243
|
stagesItems.push({ $match: this.filters });
|
|
246
244
|
if ((0, Utils_1.isNotEmpty)(this.projection)) {
|
|
247
|
-
stagesItems.push({ $project:
|
|
245
|
+
stagesItems.push({ $project: this.projection });
|
|
248
246
|
}
|
|
249
247
|
stagesItems.push({ $sort: this.sort });
|
|
250
248
|
stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 });
|
|
@@ -309,7 +307,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
309
307
|
if (!(_a < _b.length)) return [3 /*break*/, 5];
|
|
310
308
|
populate = _b[_a];
|
|
311
309
|
_c = result[0];
|
|
312
|
-
return [4 /*yield*/, model.populate(result[0].items,
|
|
310
|
+
return [4 /*yield*/, model.populate(result[0].items, populate)];
|
|
313
311
|
case 3:
|
|
314
312
|
_c.items = _d.sent();
|
|
315
313
|
_d.label = 4;
|
package/package.json
CHANGED
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// import moment from "moment"
|
|
2
|
-
import
|
|
3
|
-
import mongoose, { ClientSession, PopulateOptions, Types } from "mongoose"
|
|
2
|
+
import mongoose, { ClientSession, Types } from "mongoose"
|
|
4
3
|
import { SearchOptions, SearchResponse } from "../types/SearchResponse"
|
|
5
4
|
import { isEmpty, isNotEmpty } from "../utils/Utils"
|
|
6
|
-
import
|
|
7
|
-
import BuildSelectSingleFlowItem from "./item/BuildSelectSingleFlowItem"
|
|
5
|
+
import moment from "moment-timezone"
|
|
8
6
|
|
|
9
7
|
interface IPopulate {
|
|
10
8
|
path: string,
|
|
@@ -18,13 +16,13 @@ abstract class SearchFlow {
|
|
|
18
16
|
orderBy: string
|
|
19
17
|
page: number
|
|
20
18
|
limit: number
|
|
21
|
-
select: string[]
|
|
19
|
+
select: string | string[]
|
|
22
20
|
populate: any
|
|
23
21
|
filters: any
|
|
24
22
|
sort: any
|
|
25
23
|
pageable: boolean
|
|
26
24
|
onlyMetadata: boolean
|
|
27
|
-
projection: { [key: string]: number }
|
|
25
|
+
projection: { [key: string]: number } | undefined
|
|
28
26
|
|
|
29
27
|
constructor(params: any) {
|
|
30
28
|
// Incluir as propriedades adicionais de 'params' como propriedades da classe
|
|
@@ -170,7 +168,7 @@ abstract class SearchFlow {
|
|
|
170
168
|
stagesItems.push({ $match: this.filters })
|
|
171
169
|
|
|
172
170
|
if (isNotEmpty(this.projection)) {
|
|
173
|
-
stagesItems.push({ $project:
|
|
171
|
+
stagesItems.push({ $project: this.projection })
|
|
174
172
|
}
|
|
175
173
|
|
|
176
174
|
stagesItems.push({ $sort: this.sort })
|
|
@@ -205,7 +203,7 @@ abstract class SearchFlow {
|
|
|
205
203
|
|
|
206
204
|
if (isNotEmpty(this.populate) && Array.isArray(this.populate)) {
|
|
207
205
|
for (var populate of this.populate) {
|
|
208
|
-
result[0].items = await model.populate(result[0].items,
|
|
206
|
+
result[0].items = await model.populate(result[0].items, populate)
|
|
209
207
|
}
|
|
210
208
|
}
|
|
211
209
|
|
|
@@ -227,7 +225,7 @@ abstract class SearchFlow {
|
|
|
227
225
|
stagesItems.push({ $match: this.filters })
|
|
228
226
|
|
|
229
227
|
if (isNotEmpty(this.projection)) {
|
|
230
|
-
stagesItems.push({ $project:
|
|
228
|
+
stagesItems.push({ $project: this.projection })
|
|
231
229
|
}
|
|
232
230
|
|
|
233
231
|
stagesItems.push({ $sort: this.sort })
|
|
@@ -246,10 +244,10 @@ abstract class SearchFlow {
|
|
|
246
244
|
stagesPaging.push({ $match: this.filters })
|
|
247
245
|
stagesPaging.push({ $count: "total" })
|
|
248
246
|
stagesPaging.push(
|
|
249
|
-
{
|
|
250
|
-
$addFields: {
|
|
251
|
-
page: this.page || 1,
|
|
252
|
-
limit: this.limit,
|
|
247
|
+
{
|
|
248
|
+
$addFields: {
|
|
249
|
+
page: this.page || 1,
|
|
250
|
+
limit: this.limit,
|
|
253
251
|
totalPages: {
|
|
254
252
|
$cond: {
|
|
255
253
|
if: { $eq: ['$total', 0] },
|
|
@@ -257,9 +255,9 @@ abstract class SearchFlow {
|
|
|
257
255
|
else: { $ceil: { $divide: ['$total', this.limit] } }
|
|
258
256
|
}
|
|
259
257
|
},
|
|
260
|
-
startIndex: { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] },
|
|
258
|
+
startIndex: { $subtract: [ { $multiply: [this.page, this.limit] }, this.limit - 1 ] },
|
|
261
259
|
endIndex: { $multiply: [this.page, this.limit] }
|
|
262
|
-
}
|
|
260
|
+
}
|
|
263
261
|
})
|
|
264
262
|
|
|
265
263
|
let stagesMetadata: any[] = []
|
|
@@ -295,7 +293,7 @@ abstract class SearchFlow {
|
|
|
295
293
|
|
|
296
294
|
if (isNotEmpty(this.populate) && Array.isArray(this.populate)) {
|
|
297
295
|
for (var populate of this.populate) {
|
|
298
|
-
result[0].items = await model.populate(result[0].items,
|
|
296
|
+
result[0].items = await model.populate(result[0].items, populate)
|
|
299
297
|
}
|
|
300
298
|
}
|
|
301
299
|
|
|
@@ -489,7 +487,7 @@ abstract class SearchFlow {
|
|
|
489
487
|
condition[fieldName] = { $exists: value as boolean }
|
|
490
488
|
filters.$and.push(condition)
|
|
491
489
|
}
|
|
492
|
-
|
|
490
|
+
|
|
493
491
|
else {
|
|
494
492
|
if (!Array.isArray(value)) {
|
|
495
493
|
condition[key] = value
|
|
@@ -520,6 +518,25 @@ abstract class SearchFlow {
|
|
|
520
518
|
|
|
521
519
|
return filters
|
|
522
520
|
}
|
|
521
|
+
|
|
522
|
+
// public addFilterModel(model: any, filters: any) {
|
|
523
|
+
// Object.entries(model).forEach(([key, value]) => {
|
|
524
|
+
// if (key.endsWith('DateRange')) {
|
|
525
|
+
// return
|
|
526
|
+
// }
|
|
527
|
+
// if (key.endsWith('Like')) {
|
|
528
|
+
// return
|
|
529
|
+
// }
|
|
530
|
+
// if (['onlyMetadata', 'projection', 'pageable', 'orderSense', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
531
|
+
// return
|
|
532
|
+
// }
|
|
533
|
+
// if (isNotEmpty(value)) {
|
|
534
|
+
// let condition = {} as any
|
|
535
|
+
// condition[key] = value
|
|
536
|
+
// filters.$and.push(condition)
|
|
537
|
+
// }
|
|
538
|
+
// })
|
|
539
|
+
// }
|
|
523
540
|
}
|
|
524
541
|
|
|
525
542
|
export default SearchFlow
|