drapcode-utility 1.3.8 → 1.3.9
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 +49 -53
- 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 +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
|
|
@@ -377,7 +373,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
377
373
|
return _y = {}, _y[field] = +fieldValue, _y;
|
|
378
374
|
}
|
|
379
375
|
console.log("Nothing match");
|
|
380
|
-
return _z = {}, _z[field] = ""
|
|
376
|
+
return _z = {}, _z[field] = "" + fieldValue, _z;
|
|
381
377
|
}
|
|
382
378
|
if (key == drapcode_constant_1.NOT_EQUAL)
|
|
383
379
|
return _0 = {},
|
|
@@ -388,7 +384,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
388
384
|
},
|
|
389
385
|
_0;
|
|
390
386
|
if (key == drapcode_constant_1.BETWEEN) {
|
|
391
|
-
var _2 =
|
|
387
|
+
var _2 = exports.getMinMaxValue(fieldValue), startValue = _2.startValue, endValue = _2.endValue, isInteger = _2.isInteger;
|
|
392
388
|
return _1 = {},
|
|
393
389
|
_1[field] = {
|
|
394
390
|
$gte: isInteger ? +startValue : startValue,
|
|
@@ -457,13 +453,13 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
457
453
|
return valueList_1;
|
|
458
454
|
}
|
|
459
455
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
460
|
-
var _a =
|
|
456
|
+
var _a = exports.getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
461
457
|
if (requiredExternal) {
|
|
462
|
-
startValue_1 = ""
|
|
463
|
-
endValue_1 = ""
|
|
458
|
+
startValue_1 = "" + externalParams[startValue_1];
|
|
459
|
+
endValue_1 = "" + externalParams[endValue_1];
|
|
464
460
|
}
|
|
465
461
|
else {
|
|
466
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
462
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
467
463
|
return startValue_1.includes(cnst);
|
|
468
464
|
})) {
|
|
469
465
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser, timezone);
|
|
@@ -471,7 +467,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
471
467
|
else {
|
|
472
468
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
473
469
|
}
|
|
474
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
470
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
475
471
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser, timezone);
|
|
476
472
|
}
|
|
477
473
|
else {
|
|
@@ -487,10 +483,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
487
483
|
}
|
|
488
484
|
//TODO: Need to figure out the params should be treated as number/string
|
|
489
485
|
if (!isNaN(startValue_1)) {
|
|
490
|
-
return
|
|
486
|
+
return startValue_1 + "---" + endValue_1 + "^";
|
|
491
487
|
}
|
|
492
488
|
else
|
|
493
|
-
return
|
|
489
|
+
return startValue_1 + "---" + endValue_1;
|
|
494
490
|
}
|
|
495
491
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
496
492
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -581,18 +577,18 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
581
577
|
if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
582
578
|
return getValueOfProjectConstant(value, {}, timezone);
|
|
583
579
|
}
|
|
584
|
-
if (
|
|
580
|
+
if (exports.isEntityInCondition(value)) {
|
|
585
581
|
var key_1 = value.replace("ENTITY::", "");
|
|
586
582
|
return externalParams[key_1] ? externalParams[key_1] : "";
|
|
587
583
|
}
|
|
588
584
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
589
585
|
if (requiredExternal) {
|
|
590
586
|
//TODO: Value returns from here undefined.
|
|
591
|
-
var externalParamValue = externalParams[""
|
|
587
|
+
var externalParamValue = externalParams["" + value];
|
|
592
588
|
if (!isNaN(externalParamValue)) {
|
|
593
589
|
return +externalParamValue;
|
|
594
590
|
}
|
|
595
|
-
return externalParams[""
|
|
591
|
+
return externalParams["" + value];
|
|
596
592
|
}
|
|
597
593
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
598
594
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -623,11 +619,11 @@ var getValueOfProjectConstant = function (value, currentUser, timezone) {
|
|
|
623
619
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
624
620
|
return currentUser["uuid"];
|
|
625
621
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
626
|
-
result =
|
|
622
|
+
result = date_util_1.createLoggerDateFormat(timezone);
|
|
627
623
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
628
|
-
result =
|
|
624
|
+
result = date_util_1.createLogsDateFormat(timezone);
|
|
629
625
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
630
|
-
result =
|
|
626
|
+
result = date_util_1.getDateValue(value, timezone);
|
|
631
627
|
return result;
|
|
632
628
|
};
|
|
633
629
|
var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
@@ -643,11 +639,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
643
639
|
// if input is string and db field type is boolean
|
|
644
640
|
searchAggregateQuery.push({
|
|
645
641
|
$addFields: (_b = {},
|
|
646
|
-
_b["_"
|
|
642
|
+
_b["_" + key] = "$" + key,
|
|
647
643
|
_b),
|
|
648
644
|
});
|
|
649
645
|
likeQuery.push((_c = {},
|
|
650
|
-
_c["_"
|
|
646
|
+
_c["_" + key] = toBoolean(value),
|
|
651
647
|
_c));
|
|
652
648
|
}
|
|
653
649
|
else if ([
|
|
@@ -659,22 +655,22 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
659
655
|
// if input is string and db field type is array
|
|
660
656
|
searchAggregateQuery.push({
|
|
661
657
|
$addFields: (_d = {},
|
|
662
|
-
_d["_"
|
|
658
|
+
_d["_" + key] = "$" + key,
|
|
663
659
|
_d),
|
|
664
660
|
});
|
|
665
661
|
likeQuery.push((_e = {},
|
|
666
|
-
_e["_"
|
|
662
|
+
_e["_" + key] = { $all: [value] },
|
|
667
663
|
_e));
|
|
668
664
|
}
|
|
669
665
|
else if (searchQueryTypeKey === "tel") {
|
|
670
666
|
// handling value when db field type is tel
|
|
671
667
|
searchAggregateQuery.push({
|
|
672
668
|
$addFields: (_f = {},
|
|
673
|
-
_f["_"
|
|
669
|
+
_f["_" + key] = { $toString: "$" + key },
|
|
674
670
|
_f),
|
|
675
671
|
});
|
|
676
672
|
likeQuery.push((_g = {},
|
|
677
|
-
_g["_"
|
|
673
|
+
_g["_" + key] = {
|
|
678
674
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
679
675
|
$options: "i",
|
|
680
676
|
},
|
|
@@ -684,11 +680,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
684
680
|
// handling value when db field type is Double/Int
|
|
685
681
|
searchAggregateQuery.push({
|
|
686
682
|
$addFields: (_h = {},
|
|
687
|
-
_h["_"
|
|
683
|
+
_h["_" + key] = { $toString: { $toLong: "$" + key } },
|
|
688
684
|
_h),
|
|
689
685
|
});
|
|
690
686
|
likeQuery.push((_j = {},
|
|
691
|
-
_j["_"
|
|
687
|
+
_j["_" + key] = {
|
|
692
688
|
$regex: value,
|
|
693
689
|
$options: "i",
|
|
694
690
|
},
|
|
@@ -700,20 +696,20 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
700
696
|
fieldKey = fieldKey.replace("end_", "");
|
|
701
697
|
searchAggregateQuery.push({
|
|
702
698
|
$addFields: (_k = {},
|
|
703
|
-
_k["_"
|
|
699
|
+
_k["_" + key] = { $toString: "$" + fieldKey },
|
|
704
700
|
_k),
|
|
705
701
|
});
|
|
706
702
|
if (key.startsWith("start_")) {
|
|
707
703
|
likeQuery.push((_l = {},
|
|
708
|
-
_l["_"
|
|
709
|
-
$gte:
|
|
704
|
+
_l["_" + key] = {
|
|
705
|
+
$gte: date_util_1.timezoneDateParse(value, false, true),
|
|
710
706
|
},
|
|
711
707
|
_l));
|
|
712
708
|
}
|
|
713
709
|
else if (key.startsWith("end_")) {
|
|
714
710
|
likeQuery.push((_m = {},
|
|
715
|
-
_m["_"
|
|
716
|
-
$lt:
|
|
711
|
+
_m["_" + key] = {
|
|
712
|
+
$lt: date_util_1.timezoneDateParse(value, true),
|
|
717
713
|
},
|
|
718
714
|
_m));
|
|
719
715
|
}
|
|
@@ -724,11 +720,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
724
720
|
// converting db field to string first
|
|
725
721
|
searchAggregateQuery.push({
|
|
726
722
|
$addFields: (_o = {},
|
|
727
|
-
_o["_"
|
|
723
|
+
_o["_" + key] = { $toString: "$" + key },
|
|
728
724
|
_o),
|
|
729
725
|
});
|
|
730
726
|
likeQuery.push((_p = {},
|
|
731
|
-
_p["_"
|
|
727
|
+
_p["_" + key] = {
|
|
732
728
|
$regex: value,
|
|
733
729
|
$options: "i",
|
|
734
730
|
},
|
|
@@ -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
|
};
|