drapcode-utility 1.5.0 → 1.5.2
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/build/encryption/KMS.js +1 -1
- package/build/encryption/crypt.js +3 -3
- package/build/encryption/file.js +4 -4
- package/build/encryption/index.js +22 -26
- package/build/encryption/model.d.ts +2 -2
- package/build/encryption/utility.js +7 -11
- package/build/format-fields/index.js +1 -1
- package/build/index.js +1 -5
- package/build/middlewares/error-logger.js +6 -6
- package/build/middlewares/interceptor-logger-new.js +6 -6
- package/build/middlewares/interceptor-logger.js +3 -3
- package/build/middlewares/redis/request-log.js +4 -4
- package/build/utils/check-error.js +8 -12
- package/build/utils/date-util.js +3 -3
- package/build/utils/prepare-query.js +9 -9
- package/build/utils/query-parser.js +50 -54
- package/build/utils/query-paser-new.js +44 -48
- package/build/utils/s3-util.js +19 -22
- package/build/utils/token.js +3 -3
- package/build/utils/util.d.ts +1 -1
- package/build/utils/util.js +40 -44
- package/build/utils/uuid-generator.js +2 -2
- package/package.json +3 -3
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (
|
|
17
|
+
while (_) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -35,14 +35,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
39
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
40
|
+
to[j] = from[i];
|
|
41
|
+
return to;
|
|
46
42
|
};
|
|
47
43
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
44
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -99,7 +95,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
99
95
|
searchQueryObj = null;
|
|
100
96
|
if (searchObj) {
|
|
101
97
|
_a = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
|
|
102
|
-
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery
|
|
98
|
+
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
|
|
103
99
|
console.log("likeQuery after getSearchObjQuery", JSON.stringify(likeQuery));
|
|
104
100
|
if (likeQuery && likeQuery.length > 0) {
|
|
105
101
|
searchQueryObj = likeQuery;
|
|
@@ -122,7 +118,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
122
118
|
else if (searchObj) {
|
|
123
119
|
console.log("I donot have filter query");
|
|
124
120
|
_b = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
|
|
125
|
-
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery
|
|
121
|
+
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
|
|
126
122
|
if (likeQuery.length) {
|
|
127
123
|
aggregateQuery.push({ $match: { $and: likeQuery } });
|
|
128
124
|
}
|
|
@@ -134,13 +130,13 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
134
130
|
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy;
|
|
135
131
|
if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
|
|
136
132
|
return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
|
|
137
|
-
return
|
|
133
|
+
return prepare_query_1.commonLookupSetting(field, lookupConfig, aggregateQuery);
|
|
138
134
|
}))];
|
|
139
135
|
case 1:
|
|
140
136
|
_f.sent();
|
|
141
137
|
_f.label = 2;
|
|
142
138
|
case 2:
|
|
143
|
-
if (finder != "COUNT" && !
|
|
139
|
+
if (finder != "COUNT" && !util_1.isEmpty(projection)) {
|
|
144
140
|
aggregateQuery.push({ $project: projection });
|
|
145
141
|
}
|
|
146
142
|
if (finder === "COUNT") {
|
|
@@ -161,8 +157,8 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
161
157
|
}
|
|
162
158
|
console.log("==> aggregateQuery", aggregateQuery);
|
|
163
159
|
console.log("==> aggregateQuery", JSON.stringify(aggregateQuery));
|
|
164
|
-
queryStr = ".aggregate("
|
|
165
|
-
str = "req.db.collection('"
|
|
160
|
+
queryStr = ".aggregate(" + JSON.stringify(aggregateQuery) + ", { collation: { locale: \"en\" } })";
|
|
161
|
+
str = "req.db.collection('" + collectionName + "')" + queryStr;
|
|
166
162
|
str += ".toArray()";
|
|
167
163
|
return [2 /*return*/, str];
|
|
168
164
|
}
|
|
@@ -203,7 +199,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
|
|
|
203
199
|
filterQuery[lastKey].push(mongoQuery);
|
|
204
200
|
}
|
|
205
201
|
else {
|
|
206
|
-
filterQuery["$or"
|
|
202
|
+
filterQuery["$or" + index] = [mongoQuery];
|
|
207
203
|
}
|
|
208
204
|
}
|
|
209
205
|
else if (queryObj.conjunctionType == "AND") {
|
|
@@ -212,11 +208,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
|
|
|
212
208
|
filterQuery[lastKey].push(mongoQuery);
|
|
213
209
|
}
|
|
214
210
|
else {
|
|
215
|
-
filterQuery["$and"
|
|
211
|
+
filterQuery["$and" + index] = [mongoQuery];
|
|
216
212
|
}
|
|
217
213
|
}
|
|
218
214
|
else {
|
|
219
|
-
filterQuery["$or"
|
|
215
|
+
filterQuery["$or" + index] = [mongoQuery];
|
|
220
216
|
}
|
|
221
217
|
});
|
|
222
218
|
console.log("==> *** filterQuery mongoFilterQuery :>> ", filterQuery);
|
|
@@ -235,15 +231,15 @@ var mongoSelectQuery = function (query) {
|
|
|
235
231
|
if (fieldsInclude[0] === "*") {
|
|
236
232
|
fieldsExclude.map(function (field) {
|
|
237
233
|
if (field)
|
|
238
|
-
return (projection[""
|
|
234
|
+
return (projection["" + field] = 0);
|
|
239
235
|
});
|
|
240
236
|
}
|
|
241
237
|
else {
|
|
242
238
|
if (["FIND_ALL", "FIND"].includes(finder))
|
|
243
|
-
fieldsInclude =
|
|
239
|
+
fieldsInclude = util_1.processFieldsInlcude(fieldsInclude);
|
|
244
240
|
fieldsInclude.map(function (field) {
|
|
245
241
|
if (field)
|
|
246
|
-
return (projection[""
|
|
242
|
+
return (projection["" + field] = 1);
|
|
247
243
|
});
|
|
248
244
|
}
|
|
249
245
|
return projection;
|
|
@@ -276,7 +272,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
276
272
|
//TODO: In case of this, we assign some random string to avoid resulting all values
|
|
277
273
|
//TODO: This is use case in Spot Factor Project, where a new user with blank value able to see all records
|
|
278
274
|
//TODO: Discussed on meet
|
|
279
|
-
fieldValue = "random_string_since_field_not_present_"
|
|
275
|
+
fieldValue = "random_string_since_field_not_present_" + moment_1.default(1318874398806).valueOf();
|
|
280
276
|
}
|
|
281
277
|
console.log("fieldValue queryToMongo 1", fieldValue);
|
|
282
278
|
var isDate = checkDate(fieldValue);
|
|
@@ -344,7 +340,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
344
340
|
return _q = {},
|
|
345
341
|
_q[field] = {
|
|
346
342
|
$gte: fieldValue,
|
|
347
|
-
$lt:
|
|
343
|
+
$lt: date_util_1.nextDayDate(fieldValue),
|
|
348
344
|
},
|
|
349
345
|
_q;
|
|
350
346
|
// Todo: Remove this if works properly
|
|
@@ -392,7 +388,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
392
388
|
return _y = {}, _y[field] = +fieldValue, _y;
|
|
393
389
|
}
|
|
394
390
|
console.log("Nothing match");
|
|
395
|
-
return _z = {}, _z[field] = ""
|
|
391
|
+
return _z = {}, _z[field] = "" + fieldValue, _z;
|
|
396
392
|
}
|
|
397
393
|
if (key == drapcode_constant_1.NOT_EQUAL)
|
|
398
394
|
return _0 = {},
|
|
@@ -403,7 +399,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
403
399
|
},
|
|
404
400
|
_0;
|
|
405
401
|
if (key == drapcode_constant_1.BETWEEN) {
|
|
406
|
-
var _2 =
|
|
402
|
+
var _2 = exports.getMinMaxValue(fieldValue), startValue = _2.startValue, endValue = _2.endValue, isInteger = _2.isInteger;
|
|
407
403
|
return _1 = {},
|
|
408
404
|
_1[field] = {
|
|
409
405
|
$gte: isInteger ? +startValue : startValue,
|
|
@@ -483,7 +479,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
483
479
|
var currentDataValue = getCurrentDataValueFrom(value, cnst.constantName, cnst.data, true);
|
|
484
480
|
if (currentDataValue) {
|
|
485
481
|
valueList_1 = Array.isArray(currentDataValue)
|
|
486
|
-
? __spreadArray(__spreadArray([], valueList_1
|
|
482
|
+
? __spreadArray(__spreadArray([], valueList_1), currentDataValue) : __spreadArray(__spreadArray([], valueList_1), [currentDataValue]);
|
|
487
483
|
}
|
|
488
484
|
}
|
|
489
485
|
});
|
|
@@ -491,13 +487,13 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
491
487
|
return valueList_1;
|
|
492
488
|
}
|
|
493
489
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
494
|
-
var _a =
|
|
490
|
+
var _a = exports.getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
495
491
|
if (requiredExternal) {
|
|
496
|
-
startValue_1 = ""
|
|
497
|
-
endValue_1 = ""
|
|
492
|
+
startValue_1 = "" + externalParams[startValue_1];
|
|
493
|
+
endValue_1 = "" + externalParams[endValue_1];
|
|
498
494
|
}
|
|
499
495
|
else {
|
|
500
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
496
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
501
497
|
return startValue_1.includes(cnst);
|
|
502
498
|
})) {
|
|
503
499
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser, timezone);
|
|
@@ -505,7 +501,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
505
501
|
else {
|
|
506
502
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
507
503
|
}
|
|
508
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
504
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
509
505
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser, timezone);
|
|
510
506
|
}
|
|
511
507
|
else {
|
|
@@ -521,10 +517,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
521
517
|
}
|
|
522
518
|
//TODO: Need to figure out the params should be treated as number/string
|
|
523
519
|
if (!isNaN(startValue_1)) {
|
|
524
|
-
return
|
|
520
|
+
return startValue_1 + "---" + endValue_1 + "^";
|
|
525
521
|
}
|
|
526
522
|
else
|
|
527
|
-
return
|
|
523
|
+
return startValue_1 + "---" + endValue_1;
|
|
528
524
|
}
|
|
529
525
|
var currentUserValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_USER, currentUser);
|
|
530
526
|
console.log("\n currentUserValue :>> ", currentUserValue);
|
|
@@ -541,18 +537,18 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
541
537
|
if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
542
538
|
return getValueOfProjectConstant(value, {}, timezone);
|
|
543
539
|
}
|
|
544
|
-
if (
|
|
540
|
+
if (exports.isEntityInCondition(value)) {
|
|
545
541
|
var key_1 = value.replace("ENTITY::", "");
|
|
546
542
|
return externalParams[key_1] ? externalParams[key_1] : "";
|
|
547
543
|
}
|
|
548
544
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
549
545
|
if (requiredExternal) {
|
|
550
546
|
//TODO: Value returns from here undefined.
|
|
551
|
-
var externalParamValue = externalParams[""
|
|
547
|
+
var externalParamValue = externalParams["" + value];
|
|
552
548
|
if (!isNaN(externalParamValue)) {
|
|
553
549
|
return +externalParamValue;
|
|
554
550
|
}
|
|
555
|
-
return externalParams[""
|
|
551
|
+
return externalParams["" + value];
|
|
556
552
|
}
|
|
557
553
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
558
554
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -583,11 +579,11 @@ var getValueOfProjectConstant = function (value, currentUser, timezone) {
|
|
|
583
579
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
584
580
|
return currentUser["uuid"];
|
|
585
581
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
586
|
-
result =
|
|
582
|
+
result = date_util_1.createLoggerDateFormat(timezone);
|
|
587
583
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
588
|
-
result =
|
|
584
|
+
result = date_util_1.createLogsDateFormat(timezone);
|
|
589
585
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
590
|
-
result =
|
|
586
|
+
result = date_util_1.getDateValue(value, timezone);
|
|
591
587
|
return result;
|
|
592
588
|
};
|
|
593
589
|
var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
@@ -603,11 +599,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
603
599
|
// if input is string and db field type is boolean
|
|
604
600
|
searchAggregateQuery.push({
|
|
605
601
|
$addFields: (_b = {},
|
|
606
|
-
_b["_"
|
|
602
|
+
_b["_" + key] = "$" + key,
|
|
607
603
|
_b),
|
|
608
604
|
});
|
|
609
605
|
likeQuery.push((_c = {},
|
|
610
|
-
_c["_"
|
|
606
|
+
_c["_" + key] = toBoolean(value),
|
|
611
607
|
_c));
|
|
612
608
|
}
|
|
613
609
|
else if ([
|
|
@@ -619,22 +615,22 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
619
615
|
// if input is string and db field type is array
|
|
620
616
|
searchAggregateQuery.push({
|
|
621
617
|
$addFields: (_d = {},
|
|
622
|
-
_d["_"
|
|
618
|
+
_d["_" + key] = "$" + key,
|
|
623
619
|
_d),
|
|
624
620
|
});
|
|
625
621
|
likeQuery.push((_e = {},
|
|
626
|
-
_e["_"
|
|
622
|
+
_e["_" + key] = { $all: [value] },
|
|
627
623
|
_e));
|
|
628
624
|
}
|
|
629
625
|
else if (searchQueryTypeKey === "tel") {
|
|
630
626
|
// handling value when db field type is tel
|
|
631
627
|
searchAggregateQuery.push({
|
|
632
628
|
$addFields: (_f = {},
|
|
633
|
-
_f["_"
|
|
629
|
+
_f["_" + key] = { $toString: "$" + key },
|
|
634
630
|
_f),
|
|
635
631
|
});
|
|
636
632
|
likeQuery.push((_g = {},
|
|
637
|
-
_g["_"
|
|
633
|
+
_g["_" + key] = {
|
|
638
634
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
639
635
|
$options: "i",
|
|
640
636
|
},
|
|
@@ -644,11 +640,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
644
640
|
// handling value when db field type is Double/Int
|
|
645
641
|
searchAggregateQuery.push({
|
|
646
642
|
$addFields: (_h = {},
|
|
647
|
-
_h["_"
|
|
643
|
+
_h["_" + key] = { $toString: { $toLong: "$" + key } },
|
|
648
644
|
_h),
|
|
649
645
|
});
|
|
650
646
|
likeQuery.push((_j = {},
|
|
651
|
-
_j["_"
|
|
647
|
+
_j["_" + key] = {
|
|
652
648
|
$regex: value,
|
|
653
649
|
$options: "i",
|
|
654
650
|
},
|
|
@@ -660,20 +656,20 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
660
656
|
fieldKey = fieldKey.replace("end_", "");
|
|
661
657
|
searchAggregateQuery.push({
|
|
662
658
|
$addFields: (_k = {},
|
|
663
|
-
_k["_"
|
|
659
|
+
_k["_" + key] = { $toString: "$" + fieldKey },
|
|
664
660
|
_k),
|
|
665
661
|
});
|
|
666
662
|
if (key.startsWith("start_")) {
|
|
667
663
|
likeQuery.push((_l = {},
|
|
668
|
-
_l["_"
|
|
669
|
-
$gte:
|
|
664
|
+
_l["_" + key] = {
|
|
665
|
+
$gte: date_util_1.timezoneDateParse(value, false, true),
|
|
670
666
|
},
|
|
671
667
|
_l));
|
|
672
668
|
}
|
|
673
669
|
else if (key.startsWith("end_")) {
|
|
674
670
|
likeQuery.push((_m = {},
|
|
675
|
-
_m["_"
|
|
676
|
-
$lt:
|
|
671
|
+
_m["_" + key] = {
|
|
672
|
+
$lt: date_util_1.timezoneDateParse(value, true),
|
|
677
673
|
},
|
|
678
674
|
_m));
|
|
679
675
|
}
|
|
@@ -684,11 +680,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
684
680
|
// converting db field to string first
|
|
685
681
|
searchAggregateQuery.push({
|
|
686
682
|
$addFields: (_o = {},
|
|
687
|
-
_o["_"
|
|
683
|
+
_o["_" + key] = { $toString: "$" + key },
|
|
688
684
|
_o),
|
|
689
685
|
});
|
|
690
686
|
likeQuery.push((_p = {},
|
|
691
|
-
_p["_"
|
|
687
|
+
_p["_" + key] = {
|
|
692
688
|
$regex: value,
|
|
693
689
|
$options: "i",
|
|
694
690
|
},
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (
|
|
17
|
+
while (_) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -35,14 +35,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
39
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
40
|
+
to[j] = from[i];
|
|
41
|
+
return to;
|
|
46
42
|
};
|
|
47
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
44
|
exports.queryParserNew = void 0;
|
|
@@ -87,11 +83,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
87
83
|
if (searchQueryTypeObj[key]) {
|
|
88
84
|
aggregateQuery.push({
|
|
89
85
|
$addFields: (_b = {},
|
|
90
|
-
_b["_"
|
|
86
|
+
_b["_" + key] = { $toString: "$" + key },
|
|
91
87
|
_b),
|
|
92
88
|
});
|
|
93
89
|
searchQueryObj_1.push((_c = {},
|
|
94
|
-
_c["_"
|
|
90
|
+
_c["_" + key] = {
|
|
95
91
|
$regex: value,
|
|
96
92
|
$options: "i",
|
|
97
93
|
},
|
|
@@ -125,11 +121,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
125
121
|
// if input is string and db field type is boolean
|
|
126
122
|
aggregateQuery.push({
|
|
127
123
|
$addFields: (_b = {},
|
|
128
|
-
_b["_"
|
|
124
|
+
_b["_" + key] = "$" + key,
|
|
129
125
|
_b),
|
|
130
126
|
});
|
|
131
127
|
likeQuery_1.push((_c = {},
|
|
132
|
-
_c["_"
|
|
128
|
+
_c["_" + key] = toBoolean(value),
|
|
133
129
|
_c));
|
|
134
130
|
}
|
|
135
131
|
else if ([
|
|
@@ -141,22 +137,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
141
137
|
// if input is string and db field type is array
|
|
142
138
|
aggregateQuery.push({
|
|
143
139
|
$addFields: (_d = {},
|
|
144
|
-
_d["_"
|
|
140
|
+
_d["_" + key] = "$" + key,
|
|
145
141
|
_d),
|
|
146
142
|
});
|
|
147
143
|
likeQuery_1.push((_e = {},
|
|
148
|
-
_e["_"
|
|
144
|
+
_e["_" + key] = { $all: [value] },
|
|
149
145
|
_e));
|
|
150
146
|
}
|
|
151
147
|
else if (searchQueryTypeObj[key] === "tel") {
|
|
152
148
|
// handling value when db field type is tel
|
|
153
149
|
aggregateQuery.push({
|
|
154
150
|
$addFields: (_f = {},
|
|
155
|
-
_f["_"
|
|
151
|
+
_f["_" + key] = { $toString: "$" + key },
|
|
156
152
|
_f),
|
|
157
153
|
});
|
|
158
154
|
likeQuery_1.push((_g = {},
|
|
159
|
-
_g["_"
|
|
155
|
+
_g["_" + key] = {
|
|
160
156
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
161
157
|
$options: "i",
|
|
162
158
|
},
|
|
@@ -166,11 +162,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
166
162
|
// handling value when db field type is Double/Int
|
|
167
163
|
aggregateQuery.push({
|
|
168
164
|
$addFields: (_h = {},
|
|
169
|
-
_h["_"
|
|
165
|
+
_h["_" + key] = { $toString: { $toLong: "$" + key } },
|
|
170
166
|
_h),
|
|
171
167
|
});
|
|
172
168
|
likeQuery_1.push((_j = {},
|
|
173
|
-
_j["_"
|
|
169
|
+
_j["_" + key] = {
|
|
174
170
|
$regex: value,
|
|
175
171
|
$options: "i",
|
|
176
172
|
},
|
|
@@ -181,11 +177,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
181
177
|
// converting db field to string first
|
|
182
178
|
aggregateQuery.push({
|
|
183
179
|
$addFields: (_k = {},
|
|
184
|
-
_k["_"
|
|
180
|
+
_k["_" + key] = { $toString: "$" + key },
|
|
185
181
|
_k),
|
|
186
182
|
});
|
|
187
183
|
likeQuery_1.push((_l = {},
|
|
188
|
-
_l["_"
|
|
184
|
+
_l["_" + key] = {
|
|
189
185
|
$regex: value,
|
|
190
186
|
$options: "i",
|
|
191
187
|
},
|
|
@@ -210,14 +206,14 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
210
206
|
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy, aggregateFunctionField = query.aggregateFunctionField;
|
|
211
207
|
if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
|
|
212
208
|
return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
|
|
213
|
-
return
|
|
209
|
+
return prepare_query_1.commonLookupSetting(field, lookupConfig, aggregateQuery);
|
|
214
210
|
}))];
|
|
215
211
|
case 1:
|
|
216
212
|
_b.sent();
|
|
217
213
|
_b.label = 2;
|
|
218
214
|
case 2:
|
|
219
215
|
if (!["COUNT", "SUM", "AVG", "MIN", "MAX"].includes(finder) &&
|
|
220
|
-
!
|
|
216
|
+
!util_1.isEmpty(projection)) {
|
|
221
217
|
aggregateQuery.push({ $project: projection });
|
|
222
218
|
}
|
|
223
219
|
if (finder === "COUNT") {
|
|
@@ -225,22 +221,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
225
221
|
}
|
|
226
222
|
else if (finder === "SUM") {
|
|
227
223
|
aggregateQuery.push({
|
|
228
|
-
$group: { _id: null, total: { $sum: "$"
|
|
224
|
+
$group: { _id: null, total: { $sum: "$" + aggregateFunctionField } },
|
|
229
225
|
});
|
|
230
226
|
}
|
|
231
227
|
else if (finder === "AVG") {
|
|
232
228
|
aggregateQuery.push({
|
|
233
|
-
$group: { _id: null, average: { $avg: "$"
|
|
229
|
+
$group: { _id: null, average: { $avg: "$" + aggregateFunctionField } },
|
|
234
230
|
});
|
|
235
231
|
}
|
|
236
232
|
else if (finder === "MIN") {
|
|
237
233
|
aggregateQuery.push({
|
|
238
|
-
$group: { _id: null, minimum: { $min: "$"
|
|
234
|
+
$group: { _id: null, minimum: { $min: "$" + aggregateFunctionField } },
|
|
239
235
|
});
|
|
240
236
|
}
|
|
241
237
|
else if (finder === "MAX") {
|
|
242
238
|
aggregateQuery.push({
|
|
243
|
-
$group: { _id: null, maximum: { $max: "$"
|
|
239
|
+
$group: { _id: null, maximum: { $max: "$" + aggregateFunctionField } },
|
|
244
240
|
});
|
|
245
241
|
}
|
|
246
242
|
offset = externalParams.offset || 0;
|
|
@@ -256,8 +252,8 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
256
252
|
if (finder != "COUNT" && limit) {
|
|
257
253
|
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
258
254
|
}
|
|
259
|
-
queryStr = ".aggregate("
|
|
260
|
-
str = "req.db.collection('"
|
|
255
|
+
queryStr = ".aggregate(" + JSON.stringify(aggregateQuery) + ", { collation: { locale: \"en\" } })";
|
|
256
|
+
str = "req.db.collection('" + collectionName + "')" + queryStr;
|
|
261
257
|
str += ".toArray()";
|
|
262
258
|
return [2 /*return*/, str];
|
|
263
259
|
}
|
|
@@ -294,7 +290,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
294
290
|
filterQuery[lastKey].push(mongoQuery);
|
|
295
291
|
}
|
|
296
292
|
else {
|
|
297
|
-
filterQuery["$or"
|
|
293
|
+
filterQuery["$or" + index] = [mongoQuery];
|
|
298
294
|
}
|
|
299
295
|
}
|
|
300
296
|
else if (queryObj.conjunctionType == "AND") {
|
|
@@ -303,11 +299,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
303
299
|
filterQuery[lastKey].push(mongoQuery);
|
|
304
300
|
}
|
|
305
301
|
else {
|
|
306
|
-
filterQuery["$and"
|
|
302
|
+
filterQuery["$and" + index] = [mongoQuery];
|
|
307
303
|
}
|
|
308
304
|
}
|
|
309
305
|
else {
|
|
310
|
-
filterQuery["$or"
|
|
306
|
+
filterQuery["$or" + index] = [mongoQuery];
|
|
311
307
|
}
|
|
312
308
|
});
|
|
313
309
|
console.log("==> *** filterQuery #2 :>> ", filterQuery);
|
|
@@ -323,15 +319,15 @@ var mongoSelectQuery = function (query) {
|
|
|
323
319
|
if (fieldsInclude[0] === "*") {
|
|
324
320
|
fieldsExclude.map(function (field) {
|
|
325
321
|
if (field)
|
|
326
|
-
return (projection[""
|
|
322
|
+
return (projection["" + field] = 0);
|
|
327
323
|
});
|
|
328
324
|
}
|
|
329
325
|
else {
|
|
330
326
|
if (["FIND_ALL", "FIND"].includes(finder))
|
|
331
|
-
fieldsInclude =
|
|
327
|
+
fieldsInclude = util_1.processFieldsInlcude(fieldsInclude);
|
|
332
328
|
fieldsInclude.map(function (field) {
|
|
333
329
|
if (field)
|
|
334
|
-
return (projection[""
|
|
330
|
+
return (projection["" + field] = 1);
|
|
335
331
|
});
|
|
336
332
|
}
|
|
337
333
|
return projection;
|
|
@@ -422,7 +418,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
422
418
|
return _r = {},
|
|
423
419
|
_r[field] = {
|
|
424
420
|
$gte: fieldValue,
|
|
425
|
-
$lt: new Date(
|
|
421
|
+
$lt: new Date(date_util_1.nextDayDate(fieldValue)),
|
|
426
422
|
},
|
|
427
423
|
_r;
|
|
428
424
|
}
|
|
@@ -453,7 +449,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
453
449
|
return _z = {}, _z[field] = +fieldValue, _z;
|
|
454
450
|
}
|
|
455
451
|
console.log("Nothing match");
|
|
456
|
-
return _0 = {}, _0[field] = ""
|
|
452
|
+
return _0 = {}, _0[field] = "" + fieldValue, _0;
|
|
457
453
|
}
|
|
458
454
|
if (key == drapcode_constant_1.NOT_EQUAL)
|
|
459
455
|
return _1 = {},
|
|
@@ -519,11 +515,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
519
515
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
520
516
|
var _a = getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
521
517
|
if (requiredExternal) {
|
|
522
|
-
startValue_1 = ""
|
|
523
|
-
endValue_1 = ""
|
|
518
|
+
startValue_1 = "" + externalParams[startValue_1];
|
|
519
|
+
endValue_1 = "" + externalParams[endValue_1];
|
|
524
520
|
}
|
|
525
521
|
else {
|
|
526
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
522
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
527
523
|
return startValue_1.includes(cnst);
|
|
528
524
|
})) {
|
|
529
525
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
|
|
@@ -531,7 +527,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
531
527
|
else {
|
|
532
528
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
533
529
|
}
|
|
534
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
530
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
535
531
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
|
|
536
532
|
}
|
|
537
533
|
else {
|
|
@@ -548,10 +544,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
548
544
|
//TODO: Need to figure out the params should be treated as number/string
|
|
549
545
|
if (!isNaN(startValue_1)) {
|
|
550
546
|
console.log("I am Number");
|
|
551
|
-
return
|
|
547
|
+
return startValue_1 + "---" + endValue_1 + "^";
|
|
552
548
|
}
|
|
553
549
|
else
|
|
554
|
-
return
|
|
550
|
+
return startValue_1 + "---" + endValue_1;
|
|
555
551
|
}
|
|
556
552
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
557
553
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -589,11 +585,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
589
585
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
590
586
|
if (requiredExternal) {
|
|
591
587
|
//TODO: Value returns from here undefined.
|
|
592
|
-
var externalParamValue = externalParams[""
|
|
588
|
+
var externalParamValue = externalParams["" + value];
|
|
593
589
|
if (!isNaN(externalParamValue)) {
|
|
594
590
|
return +externalParamValue;
|
|
595
591
|
}
|
|
596
|
-
return externalParams[""
|
|
592
|
+
return externalParams["" + value];
|
|
597
593
|
}
|
|
598
594
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
599
595
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -620,9 +616,9 @@ var getValueOfProjectConstant = function (value, currentUser) {
|
|
|
620
616
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
621
617
|
return currentUser["uuid"];
|
|
622
618
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
623
|
-
return
|
|
619
|
+
return date_util_1.createLoggerDateFormat();
|
|
624
620
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
625
|
-
return
|
|
621
|
+
return date_util_1.createLogsDateFormat();
|
|
626
622
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
627
|
-
return
|
|
623
|
+
return date_util_1.getDateValue(value);
|
|
628
624
|
};
|