c2-mongoose 2.1.234 → 2.1.239
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
1
|
+
import mongoose, { Schema } from "mongoose";
|
|
2
2
|
import { SearchOptions, SearchResponse } from "../types/SearchResponse";
|
|
3
3
|
export interface IPopulate {
|
|
4
4
|
[key: string]: any;
|
|
@@ -22,6 +22,7 @@ declare class SearcherFlow<D> {
|
|
|
22
22
|
prepareSearch(search: any): void;
|
|
23
23
|
search(options: SearchOptions): Promise<SearchResponse<D>>;
|
|
24
24
|
transformObject(originalObject: any): any;
|
|
25
|
+
extractFieldsOfType(schema: Schema, typing?: string, parent?: string): string[];
|
|
25
26
|
buildDefaultFilters(objectSearch: any): any;
|
|
26
27
|
isValidObjectId(value: string): boolean;
|
|
27
28
|
buildOrdenation(): any;
|
|
@@ -46,6 +46,15 @@ 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
|
+
};
|
|
49
58
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
60
|
};
|
|
@@ -63,8 +72,8 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
63
72
|
this.page = 1;
|
|
64
73
|
this.limit = 50;
|
|
65
74
|
this.pageable = true;
|
|
66
|
-
this.select = [
|
|
67
|
-
this.populate = [
|
|
75
|
+
this.select = [];
|
|
76
|
+
this.populate = [];
|
|
68
77
|
this.filters = undefined;
|
|
69
78
|
this.model = repository;
|
|
70
79
|
}
|
|
@@ -178,12 +187,25 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
178
187
|
var hasPagination = (originalObject === null || originalObject === void 0 ? void 0 : originalObject.paging) ? true : false;
|
|
179
188
|
return __assign(__assign({}, transformedObject), { metadata: metadata, paging: hasPagination ? (originalObject === null || originalObject === void 0 ? void 0 : originalObject.paging[0]) || { total: 0, page: 1, limit: this.limit } : undefined });
|
|
180
189
|
};
|
|
190
|
+
SearcherFlow.prototype.extractFieldsOfType = function (schema, typing, parent) {
|
|
191
|
+
var _this = this;
|
|
192
|
+
if (typing === void 0) { typing = 'String'; }
|
|
193
|
+
if (parent === void 0) { parent = ''; }
|
|
194
|
+
var fieldsTyped = [];
|
|
195
|
+
Object.keys(schema.paths).forEach(function (field) {
|
|
196
|
+
if (schema.paths[field].instance === typing) {
|
|
197
|
+
fieldsTyped.push("".concat(parent !== '' ? "".concat(parent, ".") : '').concat(field));
|
|
198
|
+
}
|
|
199
|
+
else if (schema.paths[field].instance === 'Embedded') {
|
|
200
|
+
fieldsTyped = __spreadArray(__spreadArray([], fieldsTyped, true), _this.extractFieldsOfType(schema.paths[field].schema, typing, field), true);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
return fieldsTyped;
|
|
204
|
+
};
|
|
181
205
|
SearcherFlow.prototype.buildDefaultFilters = function (objectSearch) {
|
|
182
206
|
var _this = this;
|
|
183
207
|
// Recuperar todos os campos do tipo String
|
|
184
|
-
var camposString =
|
|
185
|
-
return _this.model.schema.paths[campo].instance === 'String';
|
|
186
|
-
});
|
|
208
|
+
var camposString = this.extractFieldsOfType(this.model.schema, 'String');
|
|
187
209
|
var filters = { $and: [] };
|
|
188
210
|
Object.entries(objectSearch).forEach(function (_a) {
|
|
189
211
|
var key = _a[0], value = _a[1];
|
package/package.json
CHANGED
package/src/flow/SearcherFlow.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import moment from "moment"
|
|
2
|
-
import mongoose, { ClientSession, Types } from "mongoose"
|
|
2
|
+
import mongoose, { ClientSession, Schema, Types } from "mongoose"
|
|
3
3
|
import { SearchOptions, SearchResponse } from "../types/SearchResponse"
|
|
4
4
|
import { isNotEmpty } from "../utils/Utils"
|
|
5
5
|
import BuildPopulateSingleFlowItem from "./item/BuildPopulateSingleFlowItem"
|
|
@@ -23,8 +23,8 @@ class SearcherFlow<D> {
|
|
|
23
23
|
private limit: number = 50
|
|
24
24
|
private pageable: boolean = true
|
|
25
25
|
|
|
26
|
-
private select: string[] = [
|
|
27
|
-
private populate: string[] = [
|
|
26
|
+
private select: string[] = []
|
|
27
|
+
private populate: string[] = []
|
|
28
28
|
private filters: any = undefined
|
|
29
29
|
|
|
30
30
|
constructor(repository: mongoose.Model<any>) {
|
|
@@ -152,12 +152,23 @@ class SearcherFlow<D> {
|
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
extractFieldsOfType(schema: Schema, typing = 'String', parent = ''): string[]{
|
|
156
|
+
let fieldsTyped: string[] = []
|
|
157
|
+
Object.keys(schema.paths).forEach((field: string) => {
|
|
158
|
+
if (schema.paths[field].instance === typing) {
|
|
159
|
+
fieldsTyped.push(`${parent !== '' ? `${parent}.` : ''}${field}`)
|
|
160
|
+
} else if (schema.paths[field].instance === 'Embedded') {
|
|
161
|
+
fieldsTyped = [...fieldsTyped, ...this.extractFieldsOfType(schema.paths[field].schema, typing, field)]
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
return fieldsTyped
|
|
166
|
+
}
|
|
167
|
+
|
|
155
168
|
public buildDefaultFilters(objectSearch: any) {
|
|
156
169
|
|
|
157
170
|
// Recuperar todos os campos do tipo String
|
|
158
|
-
const camposString =
|
|
159
|
-
return this.model.schema.paths[campo].instance === 'String';
|
|
160
|
-
});
|
|
171
|
+
const camposString = this.extractFieldsOfType(this.model.schema, 'String')
|
|
161
172
|
|
|
162
173
|
|
|
163
174
|
let filters = { $and: [] } as any
|