drapcode-utility 1.9.3 → 1.9.4
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.
|
@@ -128,6 +128,7 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
128
128
|
console.log("handleMultErrorConfig result :>> ".concat(Object.keys(result)));
|
|
129
129
|
apiErrorMessage = lodash_1.default.get(result, message);
|
|
130
130
|
if (apiErrorMessage) {
|
|
131
|
+
console.log("*** utility 3 ***");
|
|
131
132
|
if (typeof apiErrorMessage == "string") {
|
|
132
133
|
console.log("It's string so leave");
|
|
133
134
|
}
|
|
@@ -144,13 +145,16 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
144
145
|
apiErrorValue = lodash_1.default.get(result, path);
|
|
145
146
|
}
|
|
146
147
|
else {
|
|
148
|
+
console.log("*** utility 7 ***");
|
|
147
149
|
apiErrorValue = status;
|
|
148
150
|
}
|
|
151
|
+
console.log("*** utility 8 ***");
|
|
149
152
|
}
|
|
150
153
|
else {
|
|
151
154
|
console.log("result", result);
|
|
152
155
|
apiErrorValue = status;
|
|
153
156
|
}
|
|
157
|
+
console.log("apiErrorValue", apiErrorValue);
|
|
154
158
|
apiErrorValue = "".concat(apiErrorValue);
|
|
155
159
|
console.log("apiErrorMessage", apiErrorMessage);
|
|
156
160
|
console.log("apiErrorValue", apiErrorValue);
|
|
@@ -161,6 +165,7 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
161
165
|
};
|
|
162
166
|
}
|
|
163
167
|
else if (["false", "error", "fail", "failed"].includes(apiErrorValue.toLowerCase())) {
|
|
168
|
+
console.log("*** utility 9 ***");
|
|
164
169
|
return {
|
|
165
170
|
status: 400,
|
|
166
171
|
message: apiErrorMessage,
|
|
@@ -169,6 +174,8 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
169
174
|
else if (voca_1.default.startsWith(apiErrorValue, "3") ||
|
|
170
175
|
voca_1.default.startsWith(apiErrorValue, "4") ||
|
|
171
176
|
voca_1.default.startsWith(apiErrorValue, "5")) {
|
|
177
|
+
console.log("*** utility 10 ***");
|
|
178
|
+
console.log("Compare 4");
|
|
172
179
|
return {
|
|
173
180
|
status: apiErrorValue,
|
|
174
181
|
message: apiErrorMessage,
|
|
@@ -73,8 +73,16 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
73
73
|
if (!query)
|
|
74
74
|
return [2 /*return*/, ""];
|
|
75
75
|
console.log("***1*** queryParser ***");
|
|
76
|
+
console.log("%%%%% refCollectionFieldsInItems", JSON.stringify(refCollectionFieldsInItems));
|
|
77
|
+
console.log("%%%% timezone", timezone);
|
|
78
|
+
console.log("collectionName", collectionName);
|
|
79
|
+
console.log("query", JSON.stringify(query));
|
|
80
|
+
console.log("constants", JSON.stringify(constants));
|
|
81
|
+
console.log("externalParams", JSON.stringify(externalParams));
|
|
82
|
+
console.log("currentUser", JSON.stringify(currentUser));
|
|
83
|
+
console.log("searchObj", JSON.stringify(searchObj));
|
|
84
|
+
console.log("searchQueryTypeObj", JSON.stringify(searchQueryTypeObj));
|
|
76
85
|
filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone);
|
|
77
|
-
console.log("**************************");
|
|
78
86
|
console.log("filterQuery", JSON.stringify(filterQuery));
|
|
79
87
|
rlsFilterQuery = [];
|
|
80
88
|
if (rowLevelSecurityFilter && rowLevelSecurityFilter.conditions.length) {
|
|
@@ -92,10 +100,13 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
92
100
|
if (searchObj) {
|
|
93
101
|
_a = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
|
|
94
102
|
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery, true), searchAggregateQuery, true);
|
|
103
|
+
console.log("likeQuery after getSearchObjQuery", JSON.stringify(likeQuery));
|
|
95
104
|
if (likeQuery && likeQuery.length > 0) {
|
|
96
105
|
searchQueryObj = likeQuery;
|
|
97
106
|
}
|
|
98
107
|
}
|
|
108
|
+
console.log("aggregateQuery After search object condition", JSON.stringify(aggregateQuery));
|
|
109
|
+
console.log("searchQueryObj", JSON.stringify(searchQueryObj));
|
|
99
110
|
finalQuery = { $and: filterQuery };
|
|
100
111
|
if (rlsFilterQuery.length &&
|
|
101
112
|
((rlsFilterQuery[0].$or && rlsFilterQuery[0].$or.length) ||
|
|
@@ -105,15 +116,18 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
105
116
|
if (searchQueryObj) {
|
|
106
117
|
(_d = finalQuery.$and).push.apply(_d, searchQueryObj);
|
|
107
118
|
}
|
|
119
|
+
console.log("finalQuery after", JSON.stringify(finalQuery));
|
|
108
120
|
aggregateQuery.push({ $match: finalQuery });
|
|
109
121
|
}
|
|
110
122
|
else if (searchObj) {
|
|
123
|
+
console.log("I donot have filter query");
|
|
111
124
|
_b = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
|
|
112
125
|
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery, true), searchAggregateQuery, true);
|
|
113
126
|
if (likeQuery.length) {
|
|
114
127
|
aggregateQuery.push({ $match: { $and: likeQuery } });
|
|
115
128
|
}
|
|
116
129
|
}
|
|
130
|
+
console.log("aggregateQuery", JSON.stringify(aggregateQuery));
|
|
117
131
|
console.log("==> query", query);
|
|
118
132
|
console.log("lookupConfig", lookupConfig);
|
|
119
133
|
projection = mongoSelectQuery(query);
|
|
@@ -429,9 +443,8 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
429
443
|
if (fieldType === "number") {
|
|
430
444
|
return _6 = {}, _6[field] = +fieldValue, _6;
|
|
431
445
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
446
|
+
console.log("Nothing match");
|
|
447
|
+
return _7 = {}, _7[field] = "".concat(fieldValue), _7;
|
|
435
448
|
}
|
|
436
449
|
if (key === drapcode_constant_1.EQUALS_OR_IGNORE) {
|
|
437
450
|
if (fieldType === "boolean") {
|
|
@@ -672,7 +685,7 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
672
685
|
var searchAggregateQuery = [];
|
|
673
686
|
var likeQuery = [];
|
|
674
687
|
Object.entries(searchObj).forEach(function (_a) {
|
|
675
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
688
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
676
689
|
var key = _a[0], value = _a[1];
|
|
677
690
|
if (value) {
|
|
678
691
|
var searchQueryTypeKey = searchQueryTypeObj[key];
|
|
@@ -719,41 +732,54 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
719
732
|
_g));
|
|
720
733
|
}
|
|
721
734
|
else if (searchQueryTypeKey === "number") {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
$
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
735
|
+
if (key.startsWith("min_") || key.startsWith("max_")) {
|
|
736
|
+
var fieldKey = key.replace("min_", "");
|
|
737
|
+
fieldKey = fieldKey.replace("max_", "");
|
|
738
|
+
var numericValue = Number(value);
|
|
739
|
+
if (key.startsWith("min_")) {
|
|
740
|
+
likeQuery.push((_h = {}, _h["".concat(fieldKey)] = { $gte: numericValue }, _h));
|
|
741
|
+
}
|
|
742
|
+
else if (key.startsWith("max_")) {
|
|
743
|
+
likeQuery.push((_j = {}, _j["".concat(fieldKey)] = { $lte: numericValue }, _j));
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
// handling value when db field type is Double/Int
|
|
748
|
+
searchAggregateQuery.push({
|
|
749
|
+
$addFields: (_k = {},
|
|
750
|
+
_k["_".concat(key)] = { $toString: { $toLong: "$".concat(key) } },
|
|
751
|
+
_k),
|
|
752
|
+
});
|
|
753
|
+
likeQuery.push((_l = {},
|
|
754
|
+
_l["_".concat(key)] = {
|
|
755
|
+
$regex: value,
|
|
756
|
+
$options: "i",
|
|
757
|
+
},
|
|
758
|
+
_l));
|
|
759
|
+
}
|
|
734
760
|
}
|
|
735
761
|
else if (["date", "createdAt", "time_slot"].includes(searchQueryTypeKey)) {
|
|
736
762
|
if (key.startsWith("start_") || key.startsWith("end_")) {
|
|
737
763
|
var fieldKey = key.replace("start_", "");
|
|
738
764
|
fieldKey = fieldKey.replace("end_", "");
|
|
739
765
|
searchAggregateQuery.push({
|
|
740
|
-
$addFields: (
|
|
741
|
-
|
|
742
|
-
|
|
766
|
+
$addFields: (_m = {},
|
|
767
|
+
_m["_".concat(key)] = { $toString: "$".concat(fieldKey) },
|
|
768
|
+
_m),
|
|
743
769
|
});
|
|
744
770
|
if (key.startsWith("start_")) {
|
|
745
|
-
likeQuery.push((
|
|
746
|
-
|
|
771
|
+
likeQuery.push((_o = {},
|
|
772
|
+
_o["_".concat(key)] = {
|
|
747
773
|
$gte: (0, date_util_1.timezoneDateParse)(value, false, true),
|
|
748
774
|
},
|
|
749
|
-
|
|
775
|
+
_o));
|
|
750
776
|
}
|
|
751
777
|
else if (key.startsWith("end_")) {
|
|
752
|
-
likeQuery.push((
|
|
753
|
-
|
|
778
|
+
likeQuery.push((_p = {},
|
|
779
|
+
_p["_".concat(key)] = {
|
|
754
780
|
$lt: (0, date_util_1.timezoneDateParse)(value, true),
|
|
755
781
|
},
|
|
756
|
-
|
|
782
|
+
_p));
|
|
757
783
|
}
|
|
758
784
|
}
|
|
759
785
|
}
|
|
@@ -761,25 +787,25 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
761
787
|
// if input is string and db field type is number
|
|
762
788
|
// converting db field to string first
|
|
763
789
|
searchAggregateQuery.push({
|
|
764
|
-
$addFields: (
|
|
765
|
-
|
|
766
|
-
|
|
790
|
+
$addFields: (_q = {},
|
|
791
|
+
_q["_".concat(key)] = { $toString: "$".concat(key) },
|
|
792
|
+
_q),
|
|
767
793
|
});
|
|
768
|
-
likeQuery.push((
|
|
769
|
-
|
|
794
|
+
likeQuery.push((_r = {},
|
|
795
|
+
_r["_".concat(key)] = {
|
|
770
796
|
$regex: value,
|
|
771
797
|
$options: "i",
|
|
772
798
|
},
|
|
773
|
-
|
|
799
|
+
_r));
|
|
774
800
|
}
|
|
775
801
|
}
|
|
776
802
|
else {
|
|
777
|
-
likeQuery.push((
|
|
778
|
-
|
|
803
|
+
likeQuery.push((_s = {},
|
|
804
|
+
_s[key] = {
|
|
779
805
|
$regex: value,
|
|
780
806
|
$options: "i",
|
|
781
807
|
},
|
|
782
|
-
|
|
808
|
+
_s));
|
|
783
809
|
}
|
|
784
810
|
}
|
|
785
811
|
});
|
|
@@ -202,13 +202,10 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
|
-
console.log("==> aggregateQuery", aggregateQuery);
|
|
206
|
-
console.log("==> likeQuery", likeQuery_1);
|
|
207
205
|
if (likeQuery_1.length) {
|
|
208
206
|
aggregateQuery.push({ $match: { $and: likeQuery_1 } });
|
|
209
207
|
}
|
|
210
208
|
}
|
|
211
|
-
console.log("==> query", query);
|
|
212
209
|
projection = mongoSelectQuery(query);
|
|
213
210
|
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy, aggregateFunctionField = query.aggregateFunctionField;
|
|
214
211
|
if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
|
|
@@ -504,9 +501,8 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
504
501
|
if (fieldType === "number") {
|
|
505
502
|
return _8 = {}, _8[field] = +fieldValue, _8;
|
|
506
503
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}
|
|
504
|
+
console.log("Nothing match");
|
|
505
|
+
return _9 = {}, _9[field] = "".concat(fieldValue), _9;
|
|
510
506
|
}
|
|
511
507
|
if (key === drapcode_constant_1.EQUALS_OR_IGNORE) {
|
|
512
508
|
if (fieldType === "boolean") {
|
|
@@ -620,20 +616,16 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
620
616
|
else
|
|
621
617
|
return "".concat(startValue_1, "---").concat(endValue_1);
|
|
622
618
|
}
|
|
623
|
-
console.log("==> value", value);
|
|
624
|
-
console.log("==> currentUser", currentUser);
|
|
625
619
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
626
620
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
627
621
|
return currentUser["uuid"];
|
|
628
622
|
}
|
|
629
623
|
var splitValues = value.split("::");
|
|
630
|
-
console.log("splitValues", splitValues);
|
|
631
624
|
var refCollection = splitValues[1];
|
|
632
625
|
var refCollectionField = splitValues[2];
|
|
633
626
|
if (refCollection && refCollectionField) {
|
|
634
627
|
console.log("I have refCollection and Field");
|
|
635
628
|
var refCollectionData = currentUser[refCollection];
|
|
636
|
-
console.log("refCollectionData", refCollectionData);
|
|
637
629
|
if (!refCollectionData) {
|
|
638
630
|
return "";
|
|
639
631
|
}
|
package/build/utils/util.js
CHANGED
|
@@ -298,28 +298,34 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
298
298
|
var _a;
|
|
299
299
|
var contentList = (_a = expression
|
|
300
300
|
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
301
|
+
console.log("1 replaceDataValueIntoExpression");
|
|
301
302
|
contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
|
|
302
303
|
var needle = "{{".concat(prop, "}}");
|
|
304
|
+
console.log("needle :>> ", needle);
|
|
303
305
|
var dataOfItem = "";
|
|
304
306
|
if (prop.includes("current_user")) {
|
|
307
|
+
console.log("Current User");
|
|
305
308
|
prop = prop.replace("current_user.", "");
|
|
306
309
|
if (Object.keys(user).length > 0) {
|
|
307
310
|
dataOfItem = (0, exports.parseValueFromData)(user, prop);
|
|
308
311
|
}
|
|
309
312
|
}
|
|
310
313
|
else if (prop.includes("current_tenant")) {
|
|
314
|
+
console.log("Current Tenant");
|
|
311
315
|
prop = prop.replace("current_tenant.", "");
|
|
312
316
|
if (Object.keys(tenant).length > 0) {
|
|
313
317
|
dataOfItem = (0, exports.parseValueFromData)(tenant, prop);
|
|
314
318
|
}
|
|
315
319
|
}
|
|
316
320
|
else if (prop.includes("current_settings")) {
|
|
321
|
+
console.log("Current Setting");
|
|
317
322
|
prop = prop.replace("current_settings.", "");
|
|
318
323
|
if (Object.keys(userSetting).length > 0) {
|
|
319
324
|
dataOfItem = (0, exports.parseValueFromData)(userSetting, prop);
|
|
320
325
|
}
|
|
321
326
|
}
|
|
322
327
|
else if (prop.includes("current_session")) {
|
|
328
|
+
console.log("Current Session");
|
|
323
329
|
prop = prop.replace("current_session.", "");
|
|
324
330
|
if (Object.keys(sessionValue).length > 0) {
|
|
325
331
|
//Session will contain multi level data
|
|
@@ -327,6 +333,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
327
333
|
}
|
|
328
334
|
}
|
|
329
335
|
else if (prop.includes("form_data_session")) {
|
|
336
|
+
console.log("Form Data Session");
|
|
330
337
|
prop = prop.replace("form_data_session.", "");
|
|
331
338
|
if (Object.keys(sessionFormValue).length > 0) {
|
|
332
339
|
//Form Session will contain multi level data
|
|
@@ -334,6 +341,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
334
341
|
}
|
|
335
342
|
}
|
|
336
343
|
else if (prop.includes("SESSION_STORAGE")) {
|
|
344
|
+
console.log("Session Storage");
|
|
337
345
|
prop = prop.replace("SESSION_STORAGE.", "");
|
|
338
346
|
if (Object.keys(sessionValue).length > 0) {
|
|
339
347
|
//Session will contain multi level data
|
|
@@ -341,6 +349,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
341
349
|
}
|
|
342
350
|
}
|
|
343
351
|
else if (prop.includes("LOCAL_STORAGE")) {
|
|
352
|
+
console.log("Local Storage");
|
|
344
353
|
prop = prop.replace("LOCAL_STORAGE.", "");
|
|
345
354
|
if (Object.keys(localStorageValue).length > 0) {
|
|
346
355
|
//Session will contain multi level data
|
|
@@ -348,6 +357,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
348
357
|
}
|
|
349
358
|
}
|
|
350
359
|
else if (prop.includes("COOKIES")) {
|
|
360
|
+
console.log("Cookies");
|
|
351
361
|
prop = prop.replace("COOKIES.", "");
|
|
352
362
|
if (Object.keys(cookiesValue).length > 0) {
|
|
353
363
|
//Session will contain multi level data
|
|
@@ -355,6 +365,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
355
365
|
}
|
|
356
366
|
}
|
|
357
367
|
else if (prop.includes("environment_variable")) {
|
|
368
|
+
console.log("Environment Variable");
|
|
358
369
|
prop = prop.replace("environment_variable.", "");
|
|
359
370
|
if (Object.keys(envConstants).length > 0) {
|
|
360
371
|
var selectedConstant = envConstants.find(function (constant) { return constant.name === prop; });
|
|
@@ -362,11 +373,16 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
362
373
|
}
|
|
363
374
|
}
|
|
364
375
|
else {
|
|
376
|
+
console.log("Nothing Matches");
|
|
365
377
|
if (Object.keys(data).length > 0) {
|
|
366
378
|
dataOfItem = (0, exports.parseValueFromData)(data, prop);
|
|
379
|
+
//TODO: Need better way
|
|
380
|
+
delete data[prop];
|
|
367
381
|
}
|
|
368
382
|
}
|
|
383
|
+
console.log("dataOfItem :>> ", dataOfItem);
|
|
369
384
|
expression = replaceValueInExpression(needle, dataOfItem, expression);
|
|
385
|
+
console.log("expression :>> ", expression);
|
|
370
386
|
});
|
|
371
387
|
return expression;
|
|
372
388
|
};
|
|
@@ -425,6 +441,7 @@ var parseValueFromData = function (data, fieldName) {
|
|
|
425
441
|
else {
|
|
426
442
|
value = data ? data[fieldName] : "";
|
|
427
443
|
}
|
|
444
|
+
console.log("value :>> ", value);
|
|
428
445
|
if (value && Array.isArray(value) && typeof value[0] === "string") {
|
|
429
446
|
return value.join(", ");
|
|
430
447
|
}
|