drapcode-utility 1.4.3 → 1.4.5
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) {
|
|
@@ -574,6 +580,44 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
574
580
|
return currentTenant[refCollection];
|
|
575
581
|
return currentTenant["uuid"];
|
|
576
582
|
}
|
|
583
|
+
if (value.includes(drapcode_constant_1.CURRENT_SETTINGS)) {
|
|
584
|
+
if (value === drapcode_constant_1.CURRENT_SETTINGS) {
|
|
585
|
+
return currentUserSetting["uuid"];
|
|
586
|
+
}
|
|
587
|
+
var splitValues = value.split("::");
|
|
588
|
+
console.log("splitValues", splitValues);
|
|
589
|
+
var refCollection = "", refCollectionField = "";
|
|
590
|
+
if (splitValues.length > 2) {
|
|
591
|
+
refCollection = splitValues[1];
|
|
592
|
+
refCollectionField = splitValues[2];
|
|
593
|
+
}
|
|
594
|
+
else if (splitValues.length === 2) {
|
|
595
|
+
refCollection = splitValues[0];
|
|
596
|
+
refCollectionField = splitValues[1];
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
refCollection = splitValues[0];
|
|
600
|
+
refCollectionField = "";
|
|
601
|
+
}
|
|
602
|
+
if (refCollection && refCollectionField) {
|
|
603
|
+
console.log("I have refCollection and Field", refCollection, refCollectionField);
|
|
604
|
+
if (refCollection === "CURRENT_SETTINGS") {
|
|
605
|
+
return currentUserSetting[refCollectionField];
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
var refCollectionData = currentUserSetting[refCollection];
|
|
609
|
+
if (!refCollectionData)
|
|
610
|
+
return "";
|
|
611
|
+
if (refCollectionData.length > 1)
|
|
612
|
+
return "";
|
|
613
|
+
refCollectionData = refCollectionData[0];
|
|
614
|
+
return refCollectionData[refCollectionField];
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
if (refCollection)
|
|
618
|
+
return currentUserSetting[refCollection];
|
|
619
|
+
return currentUserSetting["uuid"];
|
|
620
|
+
}
|
|
577
621
|
if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
578
622
|
return getValueOfProjectConstant(value, {}, timezone);
|
|
579
623
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
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",
|