c2-mongoose 2.1.282 → 2.1.284
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 +1 -0
- package/dist/flow/SearcherFlow.js +53 -29
- package/package.json +1 -1
- package/src/flow/SearcherFlow.ts +54 -32
|
@@ -31,6 +31,7 @@ declare class SearcherFlow<D> {
|
|
|
31
31
|
extractFieldsOfType(schema: Schema, typing?: string, parent?: string): string[];
|
|
32
32
|
buildCondition(key: string, value: any): any;
|
|
33
33
|
buildDefaultFilters(objectSearch: any): any;
|
|
34
|
+
normalizeValue(key: string, value: any): any;
|
|
34
35
|
isValidObjectId(value: string): boolean;
|
|
35
36
|
buildOrdenation(): any;
|
|
36
37
|
buildRegex(searchText: string): RegExp;
|
|
@@ -238,16 +238,16 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
238
238
|
var values = value;
|
|
239
239
|
if ((0, Utils_1.isNotEmpty)(values[0])) {
|
|
240
240
|
var momentValue = (0, moment_1.default)(values[0]);
|
|
241
|
-
momentValue.hour(0)
|
|
242
|
-
momentValue.minute(0)
|
|
243
|
-
momentValue.second(0)
|
|
241
|
+
// momentValue.hour(0)
|
|
242
|
+
// momentValue.minute(0)
|
|
243
|
+
// momentValue.second(0)
|
|
244
244
|
condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $gte: momentValue.tz('America/Sao_Paulo', true).toDate() });
|
|
245
245
|
}
|
|
246
246
|
if ((0, Utils_1.isNotEmpty)(values[1])) {
|
|
247
247
|
var momentValue = (0, moment_1.default)(values[1]);
|
|
248
|
-
momentValue.hour(23)
|
|
249
|
-
momentValue.minute(59)
|
|
250
|
-
momentValue.second(59)
|
|
248
|
+
// momentValue.hour(23)
|
|
249
|
+
// momentValue.minute(59)
|
|
250
|
+
// momentValue.second(59)
|
|
251
251
|
condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $lte: momentValue.tz('America/Sao_Paulo', true).toDate() });
|
|
252
252
|
}
|
|
253
253
|
}
|
|
@@ -304,7 +304,7 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
304
304
|
var _this = this;
|
|
305
305
|
// Recuperar todos os campos do tipo String
|
|
306
306
|
var camposString = (0, Utils_1.isEmpty)(this.searchTextFields) ? this.extractFieldsOfType(this.model.schema, 'String') : this.searchTextFields;
|
|
307
|
-
var
|
|
307
|
+
var andQueriesParam = [];
|
|
308
308
|
Object.entries(objectSearch).forEach(function (_a) {
|
|
309
309
|
var key = _a[0], value = _a[1];
|
|
310
310
|
if ((0, Utils_1.isNotEmpty)(value) || value === null) {
|
|
@@ -341,7 +341,7 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
341
341
|
value = false;
|
|
342
342
|
}
|
|
343
343
|
var condition = _this.buildCondition(key, value);
|
|
344
|
-
|
|
344
|
+
andQueriesParam.push(condition);
|
|
345
345
|
}
|
|
346
346
|
});
|
|
347
347
|
if ((0, Utils_1.isNotEmpty)(this.searchText) && (0, Utils_1.isNotEmpty)(camposString)) {
|
|
@@ -353,31 +353,55 @@ var SearcherFlow = /** @class */ (function () {
|
|
|
353
353
|
conditionAux[fieldString] = { $regex: regex };
|
|
354
354
|
conditions.$or.push(conditionAux);
|
|
355
355
|
}
|
|
356
|
-
|
|
356
|
+
andQueriesParam.push(conditions);
|
|
357
357
|
}
|
|
358
|
-
if (filters.$and.length === 0)
|
|
359
|
-
|
|
358
|
+
// if (filters.$and.length === 0)
|
|
359
|
+
// delete filters['$and']
|
|
360
|
+
var orPayload = [];
|
|
360
361
|
if (objectSearch === null || objectSearch === void 0 ? void 0 : objectSearch.or) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
362
|
+
var _loop_1 = function (clause) {
|
|
363
|
+
if (clause.and && Array.isArray(clause.and)) {
|
|
364
|
+
var clauseAnd_1 = [];
|
|
365
|
+
Object.entries(clause.and).forEach(function (_a) {
|
|
366
|
+
var key = _a[0], value = _a[1];
|
|
367
|
+
if ((0, Utils_1.isEmpty)(value))
|
|
368
|
+
return;
|
|
369
|
+
value = _this.normalizeValue(key, value);
|
|
370
|
+
var condition = _this.buildCondition(key, value);
|
|
371
|
+
clauseAnd_1.push(condition);
|
|
372
|
+
});
|
|
373
|
+
orPayload.push(clauseAnd_1);
|
|
372
374
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
375
|
+
};
|
|
376
|
+
for (var _b = 0, _c = objectSearch === null || objectSearch === void 0 ? void 0 : objectSearch.or; _b < _c.length; _b++) {
|
|
377
|
+
var clause = _c[_b];
|
|
378
|
+
_loop_1(clause);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
var filtersFinal = {};
|
|
382
|
+
if (andQueriesParam.length > 0) {
|
|
383
|
+
if (!filtersFinal.$or)
|
|
384
|
+
filtersFinal.$or = [];
|
|
385
|
+
filtersFinal.$or = __spreadArray(__spreadArray([], filtersFinal.$or, true), [{ $and: __spreadArray([], andQueriesParam, true) }], false);
|
|
386
|
+
}
|
|
387
|
+
if (orPayload.length > 0) {
|
|
388
|
+
if (!filtersFinal.$or)
|
|
389
|
+
filtersFinal.$or = [];
|
|
390
|
+
filtersFinal.$or = __spreadArray(__spreadArray([], filtersFinal.$or, true), [{ $and: __spreadArray([], orPayload, true) }], false);
|
|
391
|
+
}
|
|
392
|
+
return filtersFinal;
|
|
393
|
+
};
|
|
394
|
+
SearcherFlow.prototype.normalizeValue = function (key, value) {
|
|
395
|
+
if (typeof value === 'string' && this.isValidObjectId(value) && key !== 'owner') {
|
|
396
|
+
value = new mongoose_1.Types.ObjectId(value);
|
|
397
|
+
}
|
|
398
|
+
if (value === 'true') {
|
|
399
|
+
value = true;
|
|
400
|
+
}
|
|
401
|
+
if (value === 'false') {
|
|
402
|
+
value = false;
|
|
379
403
|
}
|
|
380
|
-
return
|
|
404
|
+
return value;
|
|
381
405
|
};
|
|
382
406
|
SearcherFlow.prototype.isValidObjectId = function (value) {
|
|
383
407
|
var objectIdPattern = /^[0-9a-fA-F]{24}$/;
|
package/package.json
CHANGED
package/src/flow/SearcherFlow.ts
CHANGED
|
@@ -211,9 +211,9 @@ class SearcherFlow<D> {
|
|
|
211
211
|
var values = value as any
|
|
212
212
|
if (isNotEmpty(values[0])) {
|
|
213
213
|
var momentValue = moment(values[0])
|
|
214
|
-
momentValue.hour(0)
|
|
215
|
-
momentValue.minute(0)
|
|
216
|
-
momentValue.second(0)
|
|
214
|
+
// momentValue.hour(0)
|
|
215
|
+
// momentValue.minute(0)
|
|
216
|
+
// momentValue.second(0)
|
|
217
217
|
condition[fieldName] = {
|
|
218
218
|
...condition[fieldName],
|
|
219
219
|
$gte: momentValue.tz('America/Sao_Paulo', true).toDate()
|
|
@@ -222,9 +222,9 @@ class SearcherFlow<D> {
|
|
|
222
222
|
|
|
223
223
|
if (isNotEmpty(values[1])) {
|
|
224
224
|
var momentValue = moment(values[1])
|
|
225
|
-
momentValue.hour(23)
|
|
226
|
-
momentValue.minute(59)
|
|
227
|
-
momentValue.second(59)
|
|
225
|
+
// momentValue.hour(23)
|
|
226
|
+
// momentValue.minute(59)
|
|
227
|
+
// momentValue.second(59)
|
|
228
228
|
condition[fieldName] = {
|
|
229
229
|
...condition[fieldName],
|
|
230
230
|
$lte: momentValue.tz('America/Sao_Paulo', true).toDate()
|
|
@@ -285,7 +285,7 @@ class SearcherFlow<D> {
|
|
|
285
285
|
const camposString = isEmpty(this.searchTextFields) ? this.extractFieldsOfType(this.model.schema, 'String') : this.searchTextFields
|
|
286
286
|
|
|
287
287
|
|
|
288
|
-
|
|
288
|
+
const andQueriesParam = []
|
|
289
289
|
Object.entries(objectSearch).forEach(([key, value]) => {
|
|
290
290
|
if (isNotEmpty(value) || value === null) {
|
|
291
291
|
if ([
|
|
@@ -324,7 +324,7 @@ class SearcherFlow<D> {
|
|
|
324
324
|
}
|
|
325
325
|
|
|
326
326
|
const condition = this.buildCondition(key, value)
|
|
327
|
-
|
|
327
|
+
andQueriesParam.push(condition)
|
|
328
328
|
}
|
|
329
329
|
})
|
|
330
330
|
|
|
@@ -337,37 +337,59 @@ class SearcherFlow<D> {
|
|
|
337
337
|
|
|
338
338
|
conditions.$or.push(conditionAux)
|
|
339
339
|
}
|
|
340
|
-
|
|
340
|
+
andQueriesParam.push(conditions)
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
if (filters.$and.length === 0)
|
|
344
|
-
|
|
343
|
+
// if (filters.$and.length === 0)
|
|
344
|
+
// delete filters['$and']
|
|
345
345
|
|
|
346
|
+
const orPayload: any[] = []
|
|
346
347
|
if (objectSearch?.or) {
|
|
347
|
-
|
|
348
|
-
if (
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
348
|
+
for (const clause of objectSearch?.or) {
|
|
349
|
+
if (clause.and && Array.isArray(clause.and)) {
|
|
350
|
+
const clauseAnd: any[] = []
|
|
351
|
+
Object.entries(clause.and).forEach(([key, value]) => {
|
|
352
|
+
if (isEmpty(value)) return
|
|
353
|
+
value = this.normalizeValue(key, value)
|
|
354
|
+
const condition = this.buildCondition(key, value)
|
|
355
|
+
clauseAnd.push(condition)
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
orPayload.push(clauseAnd)
|
|
354
359
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const filtersFinal = {} as any
|
|
364
|
+
|
|
365
|
+
if (andQueriesParam.length > 0) {
|
|
366
|
+
if (!filtersFinal.$or) filtersFinal.$or = []
|
|
367
|
+
filtersFinal.$or = [...filtersFinal.$or, { $and: [...andQueriesParam] }]
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (orPayload.length > 0) {
|
|
371
|
+
if (!filtersFinal.$or) filtersFinal.$or = []
|
|
372
|
+
filtersFinal.$or = [...filtersFinal.$or, { $and: [...orPayload] }]
|
|
373
|
+
}
|
|
374
|
+
|
|
368
375
|
|
|
376
|
+
return filtersFinal
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
public normalizeValue(key: string, value: any): any {
|
|
380
|
+
if (typeof value === 'string' && this.isValidObjectId(value as string) && key !== 'owner') {
|
|
381
|
+
value = new Types.ObjectId(value as string)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (value === 'true') {
|
|
385
|
+
value = true
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (value === 'false') {
|
|
389
|
+
value = false
|
|
390
|
+
}
|
|
369
391
|
|
|
370
|
-
return
|
|
392
|
+
return value
|
|
371
393
|
}
|
|
372
394
|
|
|
373
395
|
public isValidObjectId(value: string) {
|