drapcode-utility 1.4.4 → 1.4.6
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const queryParser: (collectionName: string, query: any, constants: any[], externalParams: any, currentUser: any, timezone: string, searchObj?: any, refCollectionFieldsInItems?: any, searchQueryTypeObj?: any, currentTenant?: any, lookupConfig?: any) => Promise<string>;
|
|
1
|
+
export declare const queryParser: (collectionName: string, query: any, constants: any[], externalParams: any, currentUser: any, timezone: string, searchObj?: any, refCollectionFieldsInItems?: any, searchQueryTypeObj?: any, currentTenant?: any, currentUserSetting?: any, lookupConfig?: any) => Promise<string>;
|
|
2
2
|
export declare const isEntityInCondition: (value: any) => boolean;
|
|
3
3
|
export declare const getMinMaxValue: (value: any) => {
|
|
4
4
|
startValue: any;
|
|
@@ -50,12 +50,13 @@ var drapcode_constant_1 = require("drapcode-constant");
|
|
|
50
50
|
var date_util_1 = require("./date-util");
|
|
51
51
|
var util_1 = require("./util");
|
|
52
52
|
var prepare_query_1 = require("./prepare-query");
|
|
53
|
-
var queryParser = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, currentTenant, lookupConfig) {
|
|
53
|
+
var queryParser = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, currentTenant, currentUserSetting, lookupConfig) {
|
|
54
54
|
if (currentUser === void 0) { currentUser = {}; }
|
|
55
55
|
if (searchObj === void 0) { searchObj = null; }
|
|
56
56
|
if (refCollectionFieldsInItems === void 0) { refCollectionFieldsInItems = null; }
|
|
57
57
|
if (searchQueryTypeObj === void 0) { searchQueryTypeObj = {}; }
|
|
58
58
|
if (currentTenant === void 0) { currentTenant = {}; }
|
|
59
|
+
if (currentUserSetting === void 0) { currentUserSetting = {}; }
|
|
59
60
|
if (lookupConfig === void 0) { lookupConfig = []; }
|
|
60
61
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
61
62
|
var filterQuery, aggregateQuery, queryStr, searchQueryObj, _a, searchAggregateQuery, likeQuery, finalQuery, _b, searchAggregateQuery, likeQuery, projection, finder, sortBy, orderBy, offset, limit, direction, str;
|
|
@@ -77,7 +78,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
77
78
|
console.log("currentUser", JSON.stringify(currentUser));
|
|
78
79
|
console.log("searchObj", JSON.stringify(searchObj));
|
|
79
80
|
console.log("searchQueryTypeObj", JSON.stringify(searchQueryTypeObj));
|
|
80
|
-
filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant, timezone);
|
|
81
|
+
filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone);
|
|
81
82
|
console.log("filterQuery", JSON.stringify(filterQuery));
|
|
82
83
|
aggregateQuery = [];
|
|
83
84
|
queryStr = ".aggregate([])";
|
|
@@ -167,16 +168,17 @@ var toBoolean = function (value) {
|
|
|
167
168
|
return false;
|
|
168
169
|
}
|
|
169
170
|
};
|
|
170
|
-
var mongoFilterQuery = function (query, externalParams, constants, currentUser, currentTenant, timezone) {
|
|
171
|
+
var mongoFilterQuery = function (query, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone) {
|
|
171
172
|
if (currentUser === void 0) { currentUser = {}; }
|
|
172
173
|
if (currentTenant === void 0) { currentTenant = {}; }
|
|
174
|
+
if (currentUserSetting === void 0) { currentUserSetting = {}; }
|
|
173
175
|
var filterQuery = { $or0: [] };
|
|
174
176
|
var conditions = query.conditions;
|
|
175
177
|
var queryConjunctions = [];
|
|
176
178
|
conditions.forEach(function (queryObj, index) {
|
|
177
179
|
var query = queryObj.query, requiredExternal = queryObj.requiredExternal;
|
|
178
180
|
console.log("query :>> ", JSON.stringify(query));
|
|
179
|
-
var mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone);
|
|
181
|
+
var mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone);
|
|
180
182
|
console.log(":::::::::mongoQuery::::", JSON.stringify(mongoQuery));
|
|
181
183
|
queryConjunctions.push(queryObj.conjunctionType);
|
|
182
184
|
if (queryObj.conjunctionType == "OR") {
|
|
@@ -247,11 +249,12 @@ var modifyQuery = function (obj, hasAndQueryConjunction) {
|
|
|
247
249
|
console.log("🚀 ~ file: query-parser.ts:303 ~ Object.entries ~ arr:", arr);
|
|
248
250
|
return arr;
|
|
249
251
|
};
|
|
250
|
-
var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone) {
|
|
252
|
+
var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone) {
|
|
251
253
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
|
|
252
254
|
if (currentUser === void 0) { currentUser = {}; }
|
|
253
255
|
if (currentTenant === void 0) { currentTenant = {}; }
|
|
254
|
-
|
|
256
|
+
if (currentUserSetting === void 0) { currentUserSetting = {}; }
|
|
257
|
+
var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone);
|
|
255
258
|
if (["undefined", "null", null, undefined, ""].includes(fieldValue)) {
|
|
256
259
|
//TODO: In case field is not present in old record then fieldValue is undefined
|
|
257
260
|
//TODO: In case of this, we assign some random string to avoid resulting all values
|
|
@@ -408,7 +411,7 @@ var isEntityInCondition = function (value) {
|
|
|
408
411
|
return isEntity;
|
|
409
412
|
};
|
|
410
413
|
exports.isEntityInCondition = isEntityInCondition;
|
|
411
|
-
var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone) {
|
|
414
|
+
var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone) {
|
|
412
415
|
var key = query.key, value = query.value, fieldType = query.fieldType;
|
|
413
416
|
if (fieldType &&
|
|
414
417
|
!requiredExternal &&
|
|
@@ -425,6 +428,9 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
425
428
|
if (refCollection === drapcode_constant_1.CURRENT_TENANT) {
|
|
426
429
|
finalValue = currentTenant[refField];
|
|
427
430
|
}
|
|
431
|
+
if (refCollection === drapcode_constant_1.CURRENT_SETTINGS) {
|
|
432
|
+
finalValue = currentUserSetting[refField];
|
|
433
|
+
}
|
|
428
434
|
}
|
|
429
435
|
}
|
|
430
436
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -450,6 +456,22 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
450
456
|
});
|
|
451
457
|
});
|
|
452
458
|
}
|
|
459
|
+
else {
|
|
460
|
+
var constantDataObj = [
|
|
461
|
+
{ constantName: drapcode_constant_1.CURRENT_USER, data: currentUser },
|
|
462
|
+
{ constantName: drapcode_constant_1.CURRENT_TENANT, data: currentTenant },
|
|
463
|
+
{ constantName: drapcode_constant_1.CURRENT_SETTINGS, data: currentUserSetting },
|
|
464
|
+
];
|
|
465
|
+
constantDataObj.forEach(function (cnst) {
|
|
466
|
+
if (value.includes(cnst.constantName)) {
|
|
467
|
+
var currentDataValue = getCurrentDataValueFrom(value, cnst.constantName, cnst.data, true);
|
|
468
|
+
if (currentDataValue) {
|
|
469
|
+
valueList_1 = Array.isArray(currentDataValue)
|
|
470
|
+
? __spreadArray(__spreadArray([], valueList_1), currentDataValue) : __spreadArray(__spreadArray([], valueList_1), [currentDataValue]);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
453
475
|
return valueList_1;
|
|
454
476
|
}
|
|
455
477
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
@@ -488,92 +510,18 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
488
510
|
else
|
|
489
511
|
return startValue_1 + "---" + endValue_1;
|
|
490
512
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
refCollection = splitValues[0];
|
|
504
|
-
refCollectionField = splitValues[1];
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
refCollection = splitValues[0];
|
|
508
|
-
refCollectionField = "";
|
|
509
|
-
}
|
|
510
|
-
console.log("refCollection", refCollection);
|
|
511
|
-
console.log("refCollectionField", refCollectionField);
|
|
512
|
-
console.log("first", refCollectionField && refCollection);
|
|
513
|
-
if (refCollection && refCollectionField) {
|
|
514
|
-
console.log("I have refCollection and Field");
|
|
515
|
-
if (refCollection === drapcode_constant_1.CURRENT_USER) {
|
|
516
|
-
return currentUser[refCollectionField];
|
|
517
|
-
}
|
|
518
|
-
else {
|
|
519
|
-
var refCollectionData = currentUser[refCollection];
|
|
520
|
-
if (!refCollectionData) {
|
|
521
|
-
return "";
|
|
522
|
-
}
|
|
523
|
-
if (refCollectionData.length > 1) {
|
|
524
|
-
//TODO: Need to handle multi ref
|
|
525
|
-
return "";
|
|
526
|
-
}
|
|
527
|
-
refCollectionData = refCollectionData[0];
|
|
528
|
-
console.log("refCollectionData[refCollectionField]", refCollectionData[refCollectionField]);
|
|
529
|
-
return refCollectionData[refCollectionField];
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
//this means that data has to be match with currnet user field that is not ref type
|
|
533
|
-
if (refCollection) {
|
|
534
|
-
return currentUser[refCollection];
|
|
535
|
-
}
|
|
536
|
-
return currentUser["uuid"];
|
|
537
|
-
}
|
|
538
|
-
if (value.includes(drapcode_constant_1.CURRENT_TENANT)) {
|
|
539
|
-
if (value === drapcode_constant_1.CURRENT_TENANT) {
|
|
540
|
-
return currentTenant["uuid"];
|
|
541
|
-
}
|
|
542
|
-
var splitValues = value.split("::");
|
|
543
|
-
console.log("splitValues", splitValues);
|
|
544
|
-
var refCollection = "", refCollectionField = "";
|
|
545
|
-
if (splitValues.length > 2) {
|
|
546
|
-
refCollection = splitValues[1];
|
|
547
|
-
refCollectionField = splitValues[2];
|
|
548
|
-
}
|
|
549
|
-
else if (splitValues.length === 2) {
|
|
550
|
-
refCollection = splitValues[0];
|
|
551
|
-
refCollectionField = splitValues[1];
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
refCollection = splitValues[0];
|
|
555
|
-
refCollectionField = "";
|
|
556
|
-
}
|
|
557
|
-
if (refCollection && refCollectionField) {
|
|
558
|
-
console.log("I have refCollection and Field");
|
|
559
|
-
if (refCollection === "CURRENT_TENANT") {
|
|
560
|
-
return currentTenant[refCollectionField];
|
|
561
|
-
}
|
|
562
|
-
else {
|
|
563
|
-
var refCollectionData = currentTenant[refCollection];
|
|
564
|
-
if (!refCollectionData)
|
|
565
|
-
return "";
|
|
566
|
-
if (refCollectionData.length > 1)
|
|
567
|
-
return "";
|
|
568
|
-
refCollectionData = refCollectionData[0];
|
|
569
|
-
return refCollectionData[refCollectionField];
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
//this means that data has to be match with currnet user field that is not ref type
|
|
573
|
-
if (refCollection)
|
|
574
|
-
return currentTenant[refCollection];
|
|
575
|
-
return currentTenant["uuid"];
|
|
576
|
-
}
|
|
513
|
+
var currentUserValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_USER, currentUser);
|
|
514
|
+
console.log("\n currentUserValue :>> ", currentUserValue);
|
|
515
|
+
if (currentUserValue)
|
|
516
|
+
return currentUserValue;
|
|
517
|
+
var currentTenantValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_TENANT, currentTenant);
|
|
518
|
+
console.log("\n currentTenantValue :>> ", currentTenantValue);
|
|
519
|
+
if (currentTenantValue)
|
|
520
|
+
return currentTenantValue;
|
|
521
|
+
var currentUserSettingsValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_SETTINGS, currentUserSetting);
|
|
522
|
+
console.log("\n currentUserSettingsValue :>> ", currentUserSettingsValue);
|
|
523
|
+
if (currentUserSettingsValue)
|
|
524
|
+
return currentUserSettingsValue;
|
|
577
525
|
if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
578
526
|
return getValueOfProjectConstant(value, {}, timezone);
|
|
579
527
|
}
|
|
@@ -745,3 +693,59 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
745
693
|
console.log("==> likeQuery", JSON.stringify(likeQuery));
|
|
746
694
|
return { searchAggregateQuery: searchAggregateQuery, likeQuery: likeQuery };
|
|
747
695
|
};
|
|
696
|
+
var getCurrentDataValueFrom = function (value, constantName, data, isMultiRef) {
|
|
697
|
+
if (isMultiRef === void 0) { isMultiRef = false; }
|
|
698
|
+
if (value.includes(constantName)) {
|
|
699
|
+
if (value === constantName)
|
|
700
|
+
return data["uuid"];
|
|
701
|
+
var splitValues = value.split("::");
|
|
702
|
+
console.log("splitValues", splitValues);
|
|
703
|
+
var refCollection = "", refCollectionField_1 = "";
|
|
704
|
+
if (splitValues.length > 2) {
|
|
705
|
+
refCollection = splitValues[1];
|
|
706
|
+
refCollectionField_1 = splitValues[2];
|
|
707
|
+
}
|
|
708
|
+
else if (splitValues.length === 2) {
|
|
709
|
+
refCollection = splitValues[0];
|
|
710
|
+
refCollectionField_1 = splitValues[1];
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
refCollection = splitValues[0];
|
|
714
|
+
refCollectionField_1 = "";
|
|
715
|
+
}
|
|
716
|
+
console.log("refCollection", refCollection);
|
|
717
|
+
console.log("refCollectionField", refCollectionField_1);
|
|
718
|
+
console.log("first", refCollectionField_1 && refCollection);
|
|
719
|
+
if (refCollection && refCollectionField_1) {
|
|
720
|
+
console.log("I have refCollection and Field");
|
|
721
|
+
if (refCollection === constantName) {
|
|
722
|
+
return data[refCollectionField_1];
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
var refCollectionData = data[refCollection];
|
|
726
|
+
console.log("refCollectionData", refCollectionData);
|
|
727
|
+
if (!refCollectionData)
|
|
728
|
+
return "";
|
|
729
|
+
if (refCollectionData.length > 1) {
|
|
730
|
+
//TODO: Need to handle multi ref
|
|
731
|
+
// Handled For IN_LIST and NOT_IN_LIST Condition
|
|
732
|
+
if (!isMultiRef)
|
|
733
|
+
return "";
|
|
734
|
+
var finalValue_1 = [];
|
|
735
|
+
refCollectionData.forEach(function (refData) {
|
|
736
|
+
if (refData[refCollectionField_1])
|
|
737
|
+
finalValue_1.push(refData[refCollectionField_1]);
|
|
738
|
+
});
|
|
739
|
+
return finalValue_1;
|
|
740
|
+
}
|
|
741
|
+
refCollectionData = refCollectionData[0];
|
|
742
|
+
console.log("refCollectionData[refCollectionField]", refCollectionData[refCollectionField_1]);
|
|
743
|
+
return refCollectionData[refCollectionField_1];
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
//this means that data has to be match with currnet user field that is not ref type
|
|
747
|
+
if (refCollection)
|
|
748
|
+
return data[refCollection];
|
|
749
|
+
return data["uuid"];
|
|
750
|
+
}
|
|
751
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"@types/express": "^4.17.7",
|
|
34
34
|
"@types/voca": "^1.4.2",
|
|
35
35
|
"axios": "^1.1.2",
|
|
36
|
-
"drapcode-constant": "^1.
|
|
37
|
-
"drapcode-logger": "^1.1.
|
|
36
|
+
"drapcode-constant": "^1.4.0",
|
|
37
|
+
"drapcode-logger": "^1.1.4",
|
|
38
38
|
"drapcode-redis": "^1.0.5",
|
|
39
39
|
"express": "^4.17.1",
|
|
40
40
|
"lodash": "^4.17.21",
|