c2-mongoose 2.1.246 → 2.1.248
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.
|
@@ -98,11 +98,13 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
98
98
|
if ((0, Utils_1.isNotEmpty)(options.unions)) {
|
|
99
99
|
stagesItems.push.apply(stagesItems, options.unions);
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
if ((0, Utils_1.isEmpty)(options.pipelines)) {
|
|
102
|
+
stagesItems.push({ $match: this.filters });
|
|
103
|
+
if ((0, Utils_1.isNotEmpty)(this.select)) {
|
|
104
|
+
stagesItems.push({ $project: BuildSelectSingleFlowItem_1.default.build(this.model, this.select) });
|
|
105
|
+
}
|
|
106
|
+
stagesItems.push({ $sort: this.buildOrdenation() });
|
|
104
107
|
}
|
|
105
|
-
stagesItems.push({ $sort: this.buildOrdenation() });
|
|
106
108
|
if (this.pageable === true) {
|
|
107
109
|
stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 });
|
|
108
110
|
stagesItems.push({ $limit: this.limit });
|
|
@@ -16,15 +16,14 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
|
|
|
16
16
|
function BuildPopulateSingleFlowItem() {
|
|
17
17
|
}
|
|
18
18
|
BuildPopulateSingleFlowItem.prototype.buildPopulate = function (model, populatesStr, selectsStr) {
|
|
19
|
-
var _a;
|
|
20
19
|
var populateArray = [];
|
|
21
20
|
if ((0, Utils_1.isEmpty)(populatesStr)) {
|
|
22
21
|
return [];
|
|
23
22
|
}
|
|
24
23
|
var _loop_1 = function () {
|
|
25
|
-
var
|
|
24
|
+
var _a = property.split('.'), first = _a[0], rest = _a.slice(1);
|
|
26
25
|
var nested = rest.join('.');
|
|
27
|
-
var existing2 =
|
|
26
|
+
var existing2 = populateArray.find(function (populateAux) { return populateAux.path === first; });
|
|
28
27
|
var populateLocal = this_1.buildPath(first, nested, existing2);
|
|
29
28
|
//EXISTE UMA LIMITACAO DE SELECT A PARTIR DO 3 NIVEL DENTRO DOS CAMPO POPULATE, MELHORAR O CODIGO ABAIXO PARA PERCORRER MAIS NIVEIS
|
|
30
29
|
if (Array.isArray(selectsStr)) {
|
|
@@ -62,8 +61,11 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
|
|
|
62
61
|
};
|
|
63
62
|
BuildPopulateSingleFlowItem.prototype.buildPath = function (target, nested, populateAcc) {
|
|
64
63
|
// var populate = {} as IPopulate
|
|
65
|
-
var _a
|
|
64
|
+
var _a;
|
|
66
65
|
if (nested === void 0) { nested = ""; }
|
|
66
|
+
if (populateAcc === undefined) {
|
|
67
|
+
populateAcc = {};
|
|
68
|
+
}
|
|
67
69
|
if (populateAcc.path === undefined) {
|
|
68
70
|
populateAcc.path = target;
|
|
69
71
|
}
|
|
@@ -72,9 +74,9 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
|
|
|
72
74
|
populateAcc.path = populateAcc.path.trim();
|
|
73
75
|
}
|
|
74
76
|
if ((0, Utils_1.isNotEmpty)(nested)) {
|
|
75
|
-
var
|
|
77
|
+
var _b = nested.split('.'), first = _b[0], rest = _b.slice(1);
|
|
76
78
|
var nested2 = rest.join('.');
|
|
77
|
-
populateAcc.populate = __assign(__assign({}, populateAcc.populate), this.buildPath(first, nested2,
|
|
79
|
+
populateAcc.populate = __assign(__assign({}, populateAcc.populate), this.buildPath(first, nested2, populateAcc.populate));
|
|
78
80
|
}
|
|
79
81
|
return populateAcc;
|
|
80
82
|
};
|
package/package.json
CHANGED
package/src/flow/SearcherFlow.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import moment from "moment"
|
|
2
2
|
import mongoose, { ClientSession, Schema, Types } from "mongoose"
|
|
3
3
|
import { SearchOptions, SearchResponse } from "../types/SearchResponse"
|
|
4
|
-
import { isNotEmpty } from "../utils/Utils"
|
|
4
|
+
import { isEmpty, isNotEmpty } from "../utils/Utils"
|
|
5
5
|
import BuildPopulateSingleFlowItem from "./item/BuildPopulateSingleFlowItem"
|
|
6
6
|
import BuildSelectSingleFlowItem from "./item/BuildSelectSingleFlowItem"
|
|
7
7
|
export interface IPopulate {
|
|
@@ -52,13 +52,15 @@ class SearcherFlow<D> {
|
|
|
52
52
|
stagesItems.push(...options.unions)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
if (isEmpty(options.pipelines)){
|
|
56
|
+
stagesItems.push({ $match: this.filters })
|
|
57
|
+
|
|
58
|
+
if (isNotEmpty(this.select)) {
|
|
59
|
+
stagesItems.push({ $project: BuildSelectSingleFlowItem.build(this.model, this.select) })
|
|
60
|
+
}
|
|
61
|
+
stagesItems.push({ $sort: this.buildOrdenation() })
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
stagesItems.push({ $sort: this.buildOrdenation() })
|
|
62
64
|
if (this.pageable === true) {
|
|
63
65
|
stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 })
|
|
64
66
|
stagesItems.push({ $limit: this.limit })
|
|
@@ -14,7 +14,7 @@ class BuildPopulateSingleFlowItem {
|
|
|
14
14
|
let [first, ...rest] = property.split('.')
|
|
15
15
|
let nested = rest.join('.')
|
|
16
16
|
|
|
17
|
-
const existing2 = populateArray.find((populateAux: IPopulate) => populateAux.path === first)
|
|
17
|
+
const existing2 = populateArray.find((populateAux: IPopulate) => populateAux.path === first)
|
|
18
18
|
|
|
19
19
|
let populateLocal = this.buildPath(first, nested, existing2 as IPopulate)
|
|
20
20
|
|
|
@@ -55,6 +55,10 @@ class BuildPopulateSingleFlowItem {
|
|
|
55
55
|
public buildPath(target: string, nested: string = "", populateAcc: IPopulate): IPopulate {
|
|
56
56
|
// var populate = {} as IPopulate
|
|
57
57
|
|
|
58
|
+
if (populateAcc === undefined) {
|
|
59
|
+
populateAcc = {} as IPopulate
|
|
60
|
+
}
|
|
61
|
+
|
|
58
62
|
if (populateAcc.path === undefined) {
|
|
59
63
|
populateAcc.path = target
|
|
60
64
|
} else if (!populateAcc.path?.includes(target)){
|
|
@@ -67,7 +71,7 @@ class BuildPopulateSingleFlowItem {
|
|
|
67
71
|
let nested2 = rest.join('.')
|
|
68
72
|
populateAcc.populate = {
|
|
69
73
|
...populateAcc.populate,
|
|
70
|
-
...this.buildPath(first, nested2, populateAcc.populate
|
|
74
|
+
...this.buildPath(first, nested2, populateAcc.populate)
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
return populateAcc
|