c2-mongoose 2.1.276 → 2.1.278
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/SearcherFlow.d.ts +5 -0
- package/dist/flow/SearcherFlow.js +2 -2
- package/dist/flow/item/BuildPopulateSingleFlowItem.d.ts +3 -1
- package/dist/flow/item/BuildPopulateSingleFlowItem.js +20 -0
- package/package.json +1 -1
- package/src/flow/SearcherFlow.ts +9 -2
- package/src/flow/item/BuildPopulateSingleFlowItem.ts +28 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import mongoose, { Schema } from "mongoose";
|
|
2
2
|
import { SearchOptions, SearchResponse } from "../types/SearchResponse";
|
|
3
|
+
export interface IPopulate2 {
|
|
4
|
+
path: string;
|
|
5
|
+
select: string;
|
|
6
|
+
populate: IPopulate2[];
|
|
7
|
+
}
|
|
3
8
|
export interface IPopulate {
|
|
4
9
|
[key: string]: any;
|
|
5
10
|
path: string;
|
|
@@ -167,7 +167,7 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
167
167
|
result = _d.sent();
|
|
168
168
|
if (!(0, Utils_1.isNotEmpty)(this.populate)) return [3 /*break*/, 3];
|
|
169
169
|
_c = result[0];
|
|
170
|
-
return [4 /*yield*/, this.model.populate(result[0].items, BuildPopulateSingleFlowItem_1.default.
|
|
170
|
+
return [4 /*yield*/, this.model.populate(result[0].items, BuildPopulateSingleFlowItem_1.default.buildPopulate2(this.populate))];
|
|
171
171
|
case 2:
|
|
172
172
|
_c.items = _d.sent();
|
|
173
173
|
_d.label = 3;
|
|
@@ -219,7 +219,7 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
219
219
|
Object.entries(objectSearch).forEach(function (_a) {
|
|
220
220
|
var _b, _c, _d;
|
|
221
221
|
var key = _a[0], value = _a[1];
|
|
222
|
-
if ((0, Utils_1.isNotEmpty)(value)) {
|
|
222
|
+
if ((0, Utils_1.isNotEmpty)(value) || value === null) {
|
|
223
223
|
var condition = {};
|
|
224
224
|
if ([
|
|
225
225
|
'filters',
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
import { IPopulate } from "../SearcherFlow";
|
|
2
|
+
import { IPopulate, IPopulate2 } from "../SearcherFlow";
|
|
3
3
|
declare class BuildPopulateSingleFlowItem {
|
|
4
|
+
buildPopulate2(paths: string[]): IPopulate2[];
|
|
5
|
+
addPath2(root: IPopulate2[], parts: string[]): void;
|
|
4
6
|
buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[];
|
|
5
7
|
buildPath(target: string, nested: string | undefined, populateAcc: IPopulate): IPopulate;
|
|
6
8
|
}
|
|
@@ -15,6 +15,26 @@ var Utils_1 = require("../../utils/Utils");
|
|
|
15
15
|
var BuildPopulateSingleFlowItem = /** @class */ (function () {
|
|
16
16
|
function BuildPopulateSingleFlowItem() {
|
|
17
17
|
}
|
|
18
|
+
BuildPopulateSingleFlowItem.prototype.buildPopulate2 = function (paths) {
|
|
19
|
+
var _this = this;
|
|
20
|
+
var root = [];
|
|
21
|
+
paths.forEach(function (path) {
|
|
22
|
+
var parts = path.split('.');
|
|
23
|
+
_this.addPath2(root, parts);
|
|
24
|
+
});
|
|
25
|
+
return root;
|
|
26
|
+
};
|
|
27
|
+
BuildPopulateSingleFlowItem.prototype.addPath2 = function (root, parts) {
|
|
28
|
+
if (parts.length === 0)
|
|
29
|
+
return;
|
|
30
|
+
var currentPath = parts[0];
|
|
31
|
+
var existing = root.find(function (item) { return item.path === currentPath; });
|
|
32
|
+
if (!existing) {
|
|
33
|
+
existing = { path: currentPath, populate: [], select: "" };
|
|
34
|
+
root.push(existing);
|
|
35
|
+
}
|
|
36
|
+
this.addPath2(existing.populate, parts.slice(1));
|
|
37
|
+
};
|
|
18
38
|
BuildPopulateSingleFlowItem.prototype.buildPopulate = function (model, populatesStr, selectsStr) {
|
|
19
39
|
var populateArray = [];
|
|
20
40
|
if ((0, Utils_1.isEmpty)(populatesStr)) {
|
package/package.json
CHANGED
package/src/flow/SearcherFlow.ts
CHANGED
|
@@ -4,6 +4,13 @@ import { SearchOptions, SearchResponse } from "../types/SearchResponse"
|
|
|
4
4
|
import { isEmpty, isNotEmpty } from "../utils/Utils"
|
|
5
5
|
import BuildPopulateSingleFlowItem from "./item/BuildPopulateSingleFlowItem"
|
|
6
6
|
import BuildSelectSingleFlowItem from "./item/BuildSelectSingleFlowItem"
|
|
7
|
+
|
|
8
|
+
export interface IPopulate2 {
|
|
9
|
+
path: string
|
|
10
|
+
select: string
|
|
11
|
+
populate: IPopulate2[]
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
export interface IPopulate {
|
|
8
15
|
[key: string]: any
|
|
9
16
|
path: string
|
|
@@ -128,7 +135,7 @@ class SearcherFlow<D> {
|
|
|
128
135
|
|
|
129
136
|
|
|
130
137
|
if (isNotEmpty(this.populate)) {
|
|
131
|
-
result[0].items = await this.model.populate(result[0].items, BuildPopulateSingleFlowItem.
|
|
138
|
+
result[0].items = await this.model.populate(result[0].items, BuildPopulateSingleFlowItem.buildPopulate2(this.populate))
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
let resultAux = this.transformObject(result[0])
|
|
@@ -181,7 +188,7 @@ class SearcherFlow<D> {
|
|
|
181
188
|
|
|
182
189
|
let filters = { $and: [] } as any
|
|
183
190
|
Object.entries(objectSearch).forEach(([key, value]) => {
|
|
184
|
-
if (isNotEmpty(value)) {
|
|
191
|
+
if (isNotEmpty(value) || value === null) {
|
|
185
192
|
let condition = {} as any
|
|
186
193
|
if ([
|
|
187
194
|
'filters',
|
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
2
|
import { isEmpty, isNotEmpty } from "../../utils/Utils";
|
|
3
|
-
import { IPopulate } from "../SearcherFlow";
|
|
3
|
+
import { IPopulate, IPopulate2 } from "../SearcherFlow";
|
|
4
4
|
|
|
5
5
|
class BuildPopulateSingleFlowItem {
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
buildPopulate2(paths: string[]): IPopulate2[] {
|
|
9
|
+
const root: IPopulate2[] = [];
|
|
10
|
+
|
|
11
|
+
paths.forEach((path) => {
|
|
12
|
+
const parts = path.split('.');
|
|
13
|
+
this.addPath2(root, parts);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return root;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
addPath2(root: IPopulate2[], parts: string[]) {
|
|
20
|
+
if (parts.length === 0) return;
|
|
21
|
+
|
|
22
|
+
const currentPath = parts[0];
|
|
23
|
+
let existing = root.find((item) => item.path === currentPath) as IPopulate2;
|
|
24
|
+
|
|
25
|
+
if (!existing) {
|
|
26
|
+
existing = { path: currentPath, populate: [], select: "" };
|
|
27
|
+
root.push(existing as any);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.addPath2(existing.populate, parts.slice(1));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
7
34
|
public buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[] {
|
|
8
35
|
var populateArray = [] as IPopulate[]
|
|
9
36
|
if (isEmpty(populatesStr)) {
|