drapcode-utility 1.3.1 → 1.3.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 +2 -2
- package/build/encryption/file.js +4 -4
- package/build/encryption/index.js +14 -14
- package/build/encryption/model.d.ts +2 -2
- 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 +48 -52
- package/build/utils/query-paser-new.js +43 -47
- package/build/utils/s3-util.js +19 -22
- package/build/utils/util.d.ts +1 -1
- package/build/utils/util.js +22 -26
- 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 };
|
|
@@ -91,7 +87,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
91
87
|
searchQueryObj = null;
|
|
92
88
|
if (searchObj) {
|
|
93
89
|
_a = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
|
|
94
|
-
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery
|
|
90
|
+
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
|
|
95
91
|
console.log("likeQuery after getSearchObjQuery", JSON.stringify(likeQuery));
|
|
96
92
|
if (likeQuery && likeQuery.length > 0) {
|
|
97
93
|
searchQueryObj = likeQuery;
|
|
@@ -109,7 +105,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
109
105
|
else if (searchObj) {
|
|
110
106
|
console.log("I donot have filter query");
|
|
111
107
|
_b = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
|
|
112
|
-
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery
|
|
108
|
+
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
|
|
113
109
|
if (likeQuery.length) {
|
|
114
110
|
aggregateQuery.push({ $match: { $and: likeQuery } });
|
|
115
111
|
}
|
|
@@ -121,13 +117,13 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
121
117
|
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy;
|
|
122
118
|
if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
|
|
123
119
|
return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
|
|
124
|
-
return
|
|
120
|
+
return prepare_query_1.commonLookupSetting(field, lookupConfig, aggregateQuery);
|
|
125
121
|
}))];
|
|
126
122
|
case 1:
|
|
127
123
|
_e.sent();
|
|
128
124
|
_e.label = 2;
|
|
129
125
|
case 2:
|
|
130
|
-
if (finder != "COUNT" && !
|
|
126
|
+
if (finder != "COUNT" && !util_1.isEmpty(projection)) {
|
|
131
127
|
aggregateQuery.push({ $project: projection });
|
|
132
128
|
}
|
|
133
129
|
if (finder === "COUNT") {
|
|
@@ -148,8 +144,8 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
148
144
|
}
|
|
149
145
|
console.log("==> aggregateQuery", aggregateQuery);
|
|
150
146
|
console.log("==> aggregateQuery", JSON.stringify(aggregateQuery));
|
|
151
|
-
queryStr = ".aggregate("
|
|
152
|
-
str = "req.db.collection('"
|
|
147
|
+
queryStr = ".aggregate(" + JSON.stringify(aggregateQuery) + ", { collation: { locale: \"en\" } })";
|
|
148
|
+
str = "req.db.collection('" + collectionName + "')" + queryStr;
|
|
153
149
|
str += ".toArray()";
|
|
154
150
|
return [2 /*return*/, str];
|
|
155
151
|
}
|
|
@@ -189,7 +185,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
|
|
|
189
185
|
filterQuery[lastKey].push(mongoQuery);
|
|
190
186
|
}
|
|
191
187
|
else {
|
|
192
|
-
filterQuery["$or"
|
|
188
|
+
filterQuery["$or" + index] = [mongoQuery];
|
|
193
189
|
}
|
|
194
190
|
}
|
|
195
191
|
else if (queryObj.conjunctionType == "AND") {
|
|
@@ -198,11 +194,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
|
|
|
198
194
|
filterQuery[lastKey].push(mongoQuery);
|
|
199
195
|
}
|
|
200
196
|
else {
|
|
201
|
-
filterQuery["$and"
|
|
197
|
+
filterQuery["$and" + index] = [mongoQuery];
|
|
202
198
|
}
|
|
203
199
|
}
|
|
204
200
|
else {
|
|
205
|
-
filterQuery["$or"
|
|
201
|
+
filterQuery["$or" + index] = [mongoQuery];
|
|
206
202
|
}
|
|
207
203
|
});
|
|
208
204
|
console.log("==> *** filterQuery mongoFilterQuery :>> ", filterQuery);
|
|
@@ -221,15 +217,15 @@ var mongoSelectQuery = function (query) {
|
|
|
221
217
|
if (fieldsInclude[0] === "*") {
|
|
222
218
|
fieldsExclude.map(function (field) {
|
|
223
219
|
if (field)
|
|
224
|
-
return (projection[""
|
|
220
|
+
return (projection["" + field] = 0);
|
|
225
221
|
});
|
|
226
222
|
}
|
|
227
223
|
else {
|
|
228
224
|
if (["FIND_ALL", "FIND"].includes(finder))
|
|
229
|
-
fieldsInclude =
|
|
225
|
+
fieldsInclude = util_1.processFieldsInlcude(fieldsInclude);
|
|
230
226
|
fieldsInclude.map(function (field) {
|
|
231
227
|
if (field)
|
|
232
|
-
return (projection[""
|
|
228
|
+
return (projection["" + field] = 1);
|
|
233
229
|
});
|
|
234
230
|
}
|
|
235
231
|
return projection;
|
|
@@ -261,7 +257,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
261
257
|
//TODO: In case of this, we assign some random string to avoid resulting all values
|
|
262
258
|
//TODO: This is use case in Spot Factor Project, where a new user with blank value able to see all records
|
|
263
259
|
//TODO: Discussed on meet
|
|
264
|
-
fieldValue = "random_string_since_field_not_present_"
|
|
260
|
+
fieldValue = "random_string_since_field_not_present_" + moment_1.default(1318874398806).valueOf();
|
|
265
261
|
}
|
|
266
262
|
console.log("fieldValue queryToMongo 1", fieldValue);
|
|
267
263
|
var isDate = checkDate(fieldValue);
|
|
@@ -329,7 +325,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
329
325
|
return _q = {},
|
|
330
326
|
_q[field] = {
|
|
331
327
|
$gte: fieldValue,
|
|
332
|
-
$lt:
|
|
328
|
+
$lt: date_util_1.nextDayDate(fieldValue),
|
|
333
329
|
},
|
|
334
330
|
_q;
|
|
335
331
|
// Todo: Remove this if works properly
|
|
@@ -385,7 +381,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
385
381
|
},
|
|
386
382
|
_y;
|
|
387
383
|
if (key == drapcode_constant_1.BETWEEN) {
|
|
388
|
-
var _0 =
|
|
384
|
+
var _0 = exports.getMinMaxValue(fieldValue), startValue = _0.startValue, endValue = _0.endValue, isInteger = _0.isInteger;
|
|
389
385
|
return _z = {},
|
|
390
386
|
_z[field] = {
|
|
391
387
|
$gte: isInteger ? +startValue : startValue,
|
|
@@ -454,13 +450,13 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
454
450
|
return valueList_1;
|
|
455
451
|
}
|
|
456
452
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
457
|
-
var _a =
|
|
453
|
+
var _a = exports.getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
458
454
|
if (requiredExternal) {
|
|
459
|
-
startValue_1 = ""
|
|
460
|
-
endValue_1 = ""
|
|
455
|
+
startValue_1 = "" + externalParams[startValue_1];
|
|
456
|
+
endValue_1 = "" + externalParams[endValue_1];
|
|
461
457
|
}
|
|
462
458
|
else {
|
|
463
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
459
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
464
460
|
return startValue_1.includes(cnst);
|
|
465
461
|
})) {
|
|
466
462
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser, timezone);
|
|
@@ -468,7 +464,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
468
464
|
else {
|
|
469
465
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
470
466
|
}
|
|
471
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
467
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
472
468
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser, timezone);
|
|
473
469
|
}
|
|
474
470
|
else {
|
|
@@ -484,10 +480,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
484
480
|
}
|
|
485
481
|
//TODO: Need to figure out the params should be treated as number/string
|
|
486
482
|
if (!isNaN(startValue_1)) {
|
|
487
|
-
return
|
|
483
|
+
return startValue_1 + "---" + endValue_1 + "^";
|
|
488
484
|
}
|
|
489
485
|
else
|
|
490
|
-
return
|
|
486
|
+
return startValue_1 + "---" + endValue_1;
|
|
491
487
|
}
|
|
492
488
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
493
489
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -578,18 +574,18 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
578
574
|
if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
579
575
|
return getValueOfProjectConstant(value, {}, timezone);
|
|
580
576
|
}
|
|
581
|
-
if (
|
|
577
|
+
if (exports.isEntityInCondition(value)) {
|
|
582
578
|
var key_1 = value.replace("ENTITY::", "");
|
|
583
579
|
return externalParams[key_1] ? externalParams[key_1] : "";
|
|
584
580
|
}
|
|
585
581
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
586
582
|
if (requiredExternal) {
|
|
587
583
|
//TODO: Value returns from here undefined.
|
|
588
|
-
var externalParamValue = externalParams[""
|
|
584
|
+
var externalParamValue = externalParams["" + value];
|
|
589
585
|
if (!isNaN(externalParamValue)) {
|
|
590
586
|
return +externalParamValue;
|
|
591
587
|
}
|
|
592
|
-
return externalParams[""
|
|
588
|
+
return externalParams["" + value];
|
|
593
589
|
}
|
|
594
590
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
595
591
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -620,11 +616,11 @@ var getValueOfProjectConstant = function (value, currentUser, timezone) {
|
|
|
620
616
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
621
617
|
return currentUser["uuid"];
|
|
622
618
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
623
|
-
result =
|
|
619
|
+
result = date_util_1.createLoggerDateFormat(timezone);
|
|
624
620
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
625
|
-
result =
|
|
621
|
+
result = date_util_1.createLogsDateFormat(timezone);
|
|
626
622
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
627
|
-
result =
|
|
623
|
+
result = date_util_1.getDateValue(value, timezone);
|
|
628
624
|
return result;
|
|
629
625
|
};
|
|
630
626
|
var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
@@ -640,11 +636,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
640
636
|
// if input is string and db field type is boolean
|
|
641
637
|
searchAggregateQuery.push({
|
|
642
638
|
$addFields: (_b = {},
|
|
643
|
-
_b["_"
|
|
639
|
+
_b["_" + key] = "$" + key,
|
|
644
640
|
_b),
|
|
645
641
|
});
|
|
646
642
|
likeQuery.push((_c = {},
|
|
647
|
-
_c["_"
|
|
643
|
+
_c["_" + key] = toBoolean(value),
|
|
648
644
|
_c));
|
|
649
645
|
}
|
|
650
646
|
else if ([
|
|
@@ -656,22 +652,22 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
656
652
|
// if input is string and db field type is array
|
|
657
653
|
searchAggregateQuery.push({
|
|
658
654
|
$addFields: (_d = {},
|
|
659
|
-
_d["_"
|
|
655
|
+
_d["_" + key] = "$" + key,
|
|
660
656
|
_d),
|
|
661
657
|
});
|
|
662
658
|
likeQuery.push((_e = {},
|
|
663
|
-
_e["_"
|
|
659
|
+
_e["_" + key] = { $all: [value] },
|
|
664
660
|
_e));
|
|
665
661
|
}
|
|
666
662
|
else if (searchQueryTypeKey === "tel") {
|
|
667
663
|
// handling value when db field type is tel
|
|
668
664
|
searchAggregateQuery.push({
|
|
669
665
|
$addFields: (_f = {},
|
|
670
|
-
_f["_"
|
|
666
|
+
_f["_" + key] = { $toString: "$" + key },
|
|
671
667
|
_f),
|
|
672
668
|
});
|
|
673
669
|
likeQuery.push((_g = {},
|
|
674
|
-
_g["_"
|
|
670
|
+
_g["_" + key] = {
|
|
675
671
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
676
672
|
$options: "i",
|
|
677
673
|
},
|
|
@@ -681,11 +677,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
681
677
|
// handling value when db field type is Double/Int
|
|
682
678
|
searchAggregateQuery.push({
|
|
683
679
|
$addFields: (_h = {},
|
|
684
|
-
_h["_"
|
|
680
|
+
_h["_" + key] = { $toString: { $toLong: "$" + key } },
|
|
685
681
|
_h),
|
|
686
682
|
});
|
|
687
683
|
likeQuery.push((_j = {},
|
|
688
|
-
_j["_"
|
|
684
|
+
_j["_" + key] = {
|
|
689
685
|
$regex: value,
|
|
690
686
|
$options: "i",
|
|
691
687
|
},
|
|
@@ -697,20 +693,20 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
697
693
|
fieldKey = fieldKey.replace("end_", "");
|
|
698
694
|
searchAggregateQuery.push({
|
|
699
695
|
$addFields: (_k = {},
|
|
700
|
-
_k["_"
|
|
696
|
+
_k["_" + key] = { $toString: "$" + fieldKey },
|
|
701
697
|
_k),
|
|
702
698
|
});
|
|
703
699
|
if (key.startsWith("start_")) {
|
|
704
700
|
likeQuery.push((_l = {},
|
|
705
|
-
_l["_"
|
|
706
|
-
$gte:
|
|
701
|
+
_l["_" + key] = {
|
|
702
|
+
$gte: date_util_1.timezoneDateParse(value, false, true),
|
|
707
703
|
},
|
|
708
704
|
_l));
|
|
709
705
|
}
|
|
710
706
|
else if (key.startsWith("end_")) {
|
|
711
707
|
likeQuery.push((_m = {},
|
|
712
|
-
_m["_"
|
|
713
|
-
$lt:
|
|
708
|
+
_m["_" + key] = {
|
|
709
|
+
$lt: date_util_1.timezoneDateParse(value, true),
|
|
714
710
|
},
|
|
715
711
|
_m));
|
|
716
712
|
}
|
|
@@ -721,11 +717,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
721
717
|
// converting db field to string first
|
|
722
718
|
searchAggregateQuery.push({
|
|
723
719
|
$addFields: (_o = {},
|
|
724
|
-
_o["_"
|
|
720
|
+
_o["_" + key] = { $toString: "$" + key },
|
|
725
721
|
_o),
|
|
726
722
|
});
|
|
727
723
|
likeQuery.push((_p = {},
|
|
728
|
-
_p["_"
|
|
724
|
+
_p["_" + key] = {
|
|
729
725
|
$regex: value,
|
|
730
726
|
$options: "i",
|
|
731
727
|
},
|
|
@@ -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
|
}
|
|
@@ -516,11 +512,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
516
512
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
517
513
|
var _a = getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
518
514
|
if (requiredExternal) {
|
|
519
|
-
startValue_1 = ""
|
|
520
|
-
endValue_1 = ""
|
|
515
|
+
startValue_1 = "" + externalParams[startValue_1];
|
|
516
|
+
endValue_1 = "" + externalParams[endValue_1];
|
|
521
517
|
}
|
|
522
518
|
else {
|
|
523
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
519
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
524
520
|
return startValue_1.includes(cnst);
|
|
525
521
|
})) {
|
|
526
522
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
|
|
@@ -528,7 +524,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
528
524
|
else {
|
|
529
525
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
530
526
|
}
|
|
531
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
527
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
532
528
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
|
|
533
529
|
}
|
|
534
530
|
else {
|
|
@@ -545,10 +541,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
545
541
|
//TODO: Need to figure out the params should be treated as number/string
|
|
546
542
|
if (!isNaN(startValue_1)) {
|
|
547
543
|
console.log("I am Number");
|
|
548
|
-
return
|
|
544
|
+
return startValue_1 + "---" + endValue_1 + "^";
|
|
549
545
|
}
|
|
550
546
|
else
|
|
551
|
-
return
|
|
547
|
+
return startValue_1 + "---" + endValue_1;
|
|
552
548
|
}
|
|
553
549
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
554
550
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -586,11 +582,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
586
582
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
587
583
|
if (requiredExternal) {
|
|
588
584
|
//TODO: Value returns from here undefined.
|
|
589
|
-
var externalParamValue = externalParams[""
|
|
585
|
+
var externalParamValue = externalParams["" + value];
|
|
590
586
|
if (!isNaN(externalParamValue)) {
|
|
591
587
|
return +externalParamValue;
|
|
592
588
|
}
|
|
593
|
-
return externalParams[""
|
|
589
|
+
return externalParams["" + value];
|
|
594
590
|
}
|
|
595
591
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
596
592
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -617,9 +613,9 @@ var getValueOfProjectConstant = function (value, currentUser) {
|
|
|
617
613
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
618
614
|
return currentUser["uuid"];
|
|
619
615
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
620
|
-
return
|
|
616
|
+
return date_util_1.createLoggerDateFormat();
|
|
621
617
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
622
|
-
return
|
|
618
|
+
return date_util_1.createLogsDateFormat();
|
|
623
619
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
624
|
-
return
|
|
620
|
+
return date_util_1.getDateValue(value);
|
|
625
621
|
};
|