drapcode-utility 2.0.0 → 2.0.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 +54 -102
- package/build/encryption/crypt.d.ts +4 -2
- package/build/encryption/crypt.js +76 -91
- package/build/encryption/file.d.ts +0 -2
- package/build/encryption/file.js +14 -130
- package/build/encryption/index.js +162 -334
- package/build/encryption/utility.js +7 -10
- package/build/errors/app-error.js +9 -27
- package/build/errors/axios-error.js +3 -3
- package/build/errors/bad-request-error.js +10 -28
- package/build/errors/custom-error.js +5 -23
- package/build/errors/not-found.js +9 -27
- package/build/format-fields/index.d.ts +0 -1
- package/build/format-fields/index.js +32 -65
- package/build/index.d.ts +1 -4
- package/build/index.js +1 -4
- package/build/middlewares/error-logger.d.ts +1 -1
- package/build/middlewares/error-logger.js +29 -29
- package/build/middlewares/redis/request-log.js +24 -74
- package/build/query/queryBuilder.d.ts +9 -0
- package/build/query/queryBuilder.js +567 -0
- package/build/utils/check-error.d.ts +15 -8
- package/build/utils/check-error.js +71 -160
- package/build/utils/common-util.d.ts +40 -39
- package/build/utils/common-util.js +60 -59
- package/build/utils/date-util.d.ts +28 -7
- package/build/utils/date-util.js +180 -127
- package/build/utils/file-util.d.ts +51 -6
- package/build/utils/file-util.js +36 -40
- package/build/utils/prepare-query.js +70 -43
- package/build/utils/project-util.d.ts +43 -5
- package/build/utils/project-util.js +176 -121
- package/build/utils/query-parser.d.ts +1 -1
- package/build/utils/query-parser.js +289 -342
- package/build/utils/query-utils.d.ts +2 -2
- package/build/utils/query-utils.js +103 -116
- package/build/utils/rest-client.js +236 -328
- package/build/utils/s3-util.js +238 -469
- package/build/utils/token.js +34 -81
- package/build/utils/util.d.ts +58 -13
- package/build/utils/util.js +424 -494
- package/build/utils/uuid-generator.d.ts +20 -1
- package/build/utils/uuid-generator.js +111 -47
- package/package.json +7 -5
- package/build/middlewares/interceptor-logger-new.d.ts +0 -2
- package/build/middlewares/interceptor-logger-new.js +0 -53
- package/build/middlewares/interceptor-logger.d.ts +0 -2
- package/build/middlewares/interceptor-logger.js +0 -52
- package/build/utils/query-parser-new.d.ts +0 -1
- package/build/utils/query-parser-new.js +0 -541
|
@@ -1,276 +1,218 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
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
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
4
|
};
|
|
50
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
6
|
exports.isEntityInCondition = exports.queryParser = void 0;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
(_d = finalQuery.$and).push.apply(_d, searchQueryObj);
|
|
120
|
-
}
|
|
121
|
-
addTenantQuery = query.addTenantQuery, addSubTenantQuery = query.addSubTenantQuery;
|
|
122
|
-
additionalFilters = [];
|
|
123
|
-
if (addTenantQuery && (currentTenant === null || currentTenant === void 0 ? void 0 : currentTenant.uuid)) {
|
|
124
|
-
additionalFilters.push({ tenantId: currentTenant.uuid });
|
|
125
|
-
}
|
|
126
|
-
if (addSubTenantQuery &&
|
|
127
|
-
Array.isArray(currentUser.subTenantId) &&
|
|
128
|
-
currentUser.subTenantId.length > 0) {
|
|
129
|
-
subTenantUuids = currentUser.subTenantId
|
|
130
|
-
.map(function (item) { return item === null || item === void 0 ? void 0 : item.uuid; })
|
|
131
|
-
.filter(function (uuid) { return uuid; });
|
|
132
|
-
if (subTenantUuids.length > 0) {
|
|
133
|
-
additionalFilters.push({ subTenantId: { $in: subTenantUuids } });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (additionalFilters.length > 0) {
|
|
137
|
-
(_e = finalQuery.$and).push.apply(_e, additionalFilters);
|
|
138
|
-
}
|
|
139
|
-
aggregateQuery.push({ $match: finalQuery });
|
|
140
|
-
}
|
|
141
|
-
else if (searchObj) {
|
|
142
|
-
console.log("I donot have filter query");
|
|
143
|
-
_b = (0, query_utils_1.getSearchObjQuery)(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
|
|
144
|
-
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery, true), searchAggregateQuery, true);
|
|
145
|
-
if (likeQuery.length) {
|
|
146
|
-
aggregateQuery.push({ $match: { $and: likeQuery } });
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
console.log("aggregateQuery", JSON.stringify(aggregateQuery));
|
|
150
|
-
console.log("==> query", query);
|
|
151
|
-
console.log("lookupConfig", lookupConfig);
|
|
152
|
-
projection = (0, query_utils_1.mongoSelectQuery)(query);
|
|
153
|
-
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy;
|
|
154
|
-
if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
|
|
155
|
-
return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
|
|
156
|
-
return (0, prepare_query_1.commonLookupSetting)(field, lookupConfig, aggregateQuery);
|
|
157
|
-
}))];
|
|
158
|
-
case 1:
|
|
159
|
-
_g.sent();
|
|
160
|
-
_g.label = 2;
|
|
161
|
-
case 2:
|
|
162
|
-
if (finder != "COUNT" && !(0, util_1.isEmpty)(projection)) {
|
|
163
|
-
aggregateQuery.push({ $project: projection });
|
|
164
|
-
}
|
|
165
|
-
if (finder === "COUNT") {
|
|
166
|
-
aggregateQuery.push({ $group: { _id: null, count: { $sum: 1 } } });
|
|
167
|
-
}
|
|
168
|
-
offset = externalParams.offset || 0;
|
|
169
|
-
limit = externalParams.limit || 20000;
|
|
170
|
-
resetLimit = externalParams.resetLimit || false;
|
|
171
|
-
if (externalParams.pagination == "false") {
|
|
172
|
-
limit = 0;
|
|
173
|
-
sortBy = 0;
|
|
174
|
-
}
|
|
175
|
-
// Reset limit value to 1 in case filter is of type FIND or when it's a COUNT finder for FIND filter
|
|
176
|
-
if (finder === "FIND" || (finder === "COUNT" && resetLimit)) {
|
|
177
|
-
offset = 0;
|
|
178
|
-
limit = 1;
|
|
179
|
-
}
|
|
180
|
-
if (finder != "COUNT" && sortBy) {
|
|
181
|
-
direction = orderBy && orderBy == "asc" ? 1 : -1;
|
|
182
|
-
aggregateQuery.push({ $sort: (_f = {}, _f[sortBy] = direction, _f._id = 1, _f) });
|
|
183
|
-
}
|
|
184
|
-
if (finder != "COUNT" && limit) {
|
|
185
|
-
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
186
|
-
}
|
|
187
|
-
console.log("==> aggregateQuery", aggregateQuery);
|
|
188
|
-
return [2 /*return*/, aggregateQuery];
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const drapcode_constant_1 = require("drapcode-constant");
|
|
9
|
+
const date_util_1 = require("./date-util");
|
|
10
|
+
const util_1 = require("./util");
|
|
11
|
+
const prepare_query_1 = require("./prepare-query");
|
|
12
|
+
const query_utils_1 = require("./query-utils");
|
|
13
|
+
const queryParser = async (collectionName, query, constants, externalParams, currentUser = {}, timezone, searchObj = null, refCollectionFieldsInItems = null, searchQueryTypeObj = {}, currentTenant = {}, currentUserSetting = {}, currentSubTenant = {}, lookupConfig = [], rowLevelSecurityFilter) => {
|
|
14
|
+
if (!collectionName)
|
|
15
|
+
return "";
|
|
16
|
+
if (!query)
|
|
17
|
+
return "";
|
|
18
|
+
console.log("***1*** queryParser ***");
|
|
19
|
+
console.log("%%%%% refCollectionFieldsInItems", JSON.stringify(refCollectionFieldsInItems));
|
|
20
|
+
console.log("%%%% timezone", timezone);
|
|
21
|
+
console.log("collectionName", collectionName);
|
|
22
|
+
console.log("query", JSON.stringify(query));
|
|
23
|
+
console.log("constants", JSON.stringify(constants));
|
|
24
|
+
console.log("externalParams", JSON.stringify(externalParams));
|
|
25
|
+
console.log("currentUser", JSON.stringify(currentUser));
|
|
26
|
+
console.log("searchObj", JSON.stringify(searchObj));
|
|
27
|
+
console.log("searchQueryTypeObj", JSON.stringify(searchQueryTypeObj));
|
|
28
|
+
let filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
|
|
29
|
+
console.log(`filterQuery`, JSON.stringify(filterQuery));
|
|
30
|
+
let rlsFilterQuery = [];
|
|
31
|
+
if (rowLevelSecurityFilter && rowLevelSecurityFilter.conditions.length) {
|
|
32
|
+
rlsFilterQuery = mongoFilterQuery(rowLevelSecurityFilter, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
|
|
33
|
+
console.log("**************************");
|
|
34
|
+
console.log(`rlsFilterQuery`, JSON.stringify(rlsFilterQuery));
|
|
35
|
+
}
|
|
36
|
+
console.log(`==> searchQueryTypeObj :>>`, searchQueryTypeObj);
|
|
37
|
+
let aggregateQuery = [];
|
|
38
|
+
if (filterQuery.length &&
|
|
39
|
+
((filterQuery[0].$or && filterQuery[0].$or.length) ||
|
|
40
|
+
(filterQuery[0].$and && filterQuery[0].$and.length))) {
|
|
41
|
+
let searchQueryObj = null;
|
|
42
|
+
if (searchObj) {
|
|
43
|
+
const { searchAggregateQuery, likeQuery } = (0, query_utils_1.getSearchObjQuery)(searchObj, searchQueryTypeObj);
|
|
44
|
+
aggregateQuery = [...aggregateQuery, ...searchAggregateQuery];
|
|
45
|
+
console.log("likeQuery after getSearchObjQuery", JSON.stringify(likeQuery));
|
|
46
|
+
if (likeQuery && likeQuery.length > 0) {
|
|
47
|
+
searchQueryObj = likeQuery;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log("aggregateQuery After search object condition", JSON.stringify(aggregateQuery));
|
|
51
|
+
console.log("searchQueryObj", JSON.stringify(searchQueryObj));
|
|
52
|
+
let finalQuery = { $and: filterQuery };
|
|
53
|
+
if (rlsFilterQuery.length &&
|
|
54
|
+
((rlsFilterQuery[0].$or && rlsFilterQuery[0].$or.length) ||
|
|
55
|
+
(rlsFilterQuery[0].$and && rlsFilterQuery[0].$and.length))) {
|
|
56
|
+
finalQuery.$and.push(...rlsFilterQuery);
|
|
57
|
+
}
|
|
58
|
+
if (searchQueryObj) {
|
|
59
|
+
finalQuery.$and.push(...searchQueryObj);
|
|
60
|
+
}
|
|
61
|
+
const { addTenantQuery, addSubTenantQuery } = query;
|
|
62
|
+
const additionalFilters = [];
|
|
63
|
+
if (addTenantQuery && currentTenant?.uuid) {
|
|
64
|
+
additionalFilters.push({ tenantId: currentTenant.uuid });
|
|
65
|
+
}
|
|
66
|
+
if (addSubTenantQuery &&
|
|
67
|
+
Array.isArray(currentUser.subTenantId) &&
|
|
68
|
+
currentUser.subTenantId.length > 0) {
|
|
69
|
+
const subTenantUuids = currentUser.subTenantId
|
|
70
|
+
.map((item) => item?.uuid)
|
|
71
|
+
.filter((uuid) => uuid); // Filters out undefined/null
|
|
72
|
+
if (subTenantUuids.length > 0) {
|
|
73
|
+
additionalFilters.push({ subTenantId: { $in: subTenantUuids } });
|
|
189
74
|
}
|
|
75
|
+
}
|
|
76
|
+
if (additionalFilters.length > 0) {
|
|
77
|
+
finalQuery.$and.push(...additionalFilters);
|
|
78
|
+
}
|
|
79
|
+
aggregateQuery.push({ $match: finalQuery });
|
|
80
|
+
}
|
|
81
|
+
else if (searchObj) {
|
|
82
|
+
console.log("I donot have filter query");
|
|
83
|
+
const { searchAggregateQuery, likeQuery } = (0, query_utils_1.getSearchObjQuery)(searchObj, searchQueryTypeObj);
|
|
84
|
+
aggregateQuery = [...aggregateQuery, ...searchAggregateQuery];
|
|
85
|
+
if (likeQuery.length) {
|
|
86
|
+
aggregateQuery.push({ $match: { $and: likeQuery } });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
console.log(`==> query`, query);
|
|
90
|
+
console.log("lookupConfig", lookupConfig);
|
|
91
|
+
let projection = (0, query_utils_1.mongoSelectQuery)(query);
|
|
92
|
+
let { finder, sortBy, orderBy, aggregateFunctionField } = query;
|
|
93
|
+
if (finder != "COUNT" && refCollectionFieldsInItems) {
|
|
94
|
+
await Promise.all(refCollectionFieldsInItems.map((field) => (0, prepare_query_1.commonLookupSetting)(field, lookupConfig, aggregateQuery)));
|
|
95
|
+
}
|
|
96
|
+
if (!util_1.nonFindQuery.includes(finder) && !(0, util_1.isEmpty)(projection)) {
|
|
97
|
+
aggregateQuery.push({ $project: projection });
|
|
98
|
+
}
|
|
99
|
+
if (finder === "COUNT") {
|
|
100
|
+
aggregateQuery.push({ $group: { _id: null, count: { $sum: 1 } } });
|
|
101
|
+
}
|
|
102
|
+
else if (finder === "SUM") {
|
|
103
|
+
aggregateQuery.push({
|
|
104
|
+
$group: { _id: null, total: { $sum: `$${aggregateFunctionField}` } },
|
|
190
105
|
});
|
|
191
|
-
}
|
|
106
|
+
}
|
|
107
|
+
else if (finder === "AVG") {
|
|
108
|
+
aggregateQuery.push({
|
|
109
|
+
$group: { _id: null, average: { $avg: `$${aggregateFunctionField}` } },
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else if (finder === "MIN") {
|
|
113
|
+
aggregateQuery.push({
|
|
114
|
+
$group: { _id: null, minimum: { $min: `$${aggregateFunctionField}` } },
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else if (finder === "MAX") {
|
|
118
|
+
aggregateQuery.push({
|
|
119
|
+
$group: { _id: null, maximum: { $max: `$${aggregateFunctionField}` } },
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
let offset = externalParams.offset || 0;
|
|
123
|
+
let limit = externalParams.limit || 20000;
|
|
124
|
+
let resetLimit = externalParams.resetLimit || false;
|
|
125
|
+
if (externalParams.pagination == "false") {
|
|
126
|
+
limit = 0;
|
|
127
|
+
sortBy = 0;
|
|
128
|
+
}
|
|
129
|
+
// Reset limit value to 1 in case filter is of type FIND or when it's a COUNT finder for FIND filter
|
|
130
|
+
if (finder === "FIND" || (util_1.nonFindQuery.includes(finder) && resetLimit)) {
|
|
131
|
+
offset = 0;
|
|
132
|
+
limit = 1;
|
|
133
|
+
}
|
|
134
|
+
if (!util_1.nonFindQuery.includes(finder) && sortBy) {
|
|
135
|
+
let direction = orderBy && orderBy == "asc" ? 1 : -1;
|
|
136
|
+
aggregateQuery.push({ $sort: { [sortBy]: direction, _id: 1 } });
|
|
137
|
+
}
|
|
138
|
+
if (!util_1.nonFindQuery.includes(finder) && limit) {
|
|
139
|
+
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
140
|
+
}
|
|
141
|
+
console.log(`==> aggregateQuery`, aggregateQuery);
|
|
142
|
+
return aggregateQuery;
|
|
192
143
|
};
|
|
193
144
|
exports.queryParser = queryParser;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
var conditions = query.conditions;
|
|
201
|
-
var queryConjunctions = [];
|
|
202
|
-
conditions.forEach(function (queryObj, index) {
|
|
203
|
-
var query = queryObj.query, requiredExternal = queryObj.requiredExternal;
|
|
145
|
+
const mongoFilterQuery = (query, externalParams, constants, currentUser = {}, currentTenant = {}, currentUserSetting = {}, currentSubTenant = {}, timezone) => {
|
|
146
|
+
let filterQuery = { $or0: [] };
|
|
147
|
+
let { conditions } = query;
|
|
148
|
+
let queryConjunctions = [];
|
|
149
|
+
conditions.forEach((queryObj, index) => {
|
|
150
|
+
const { query, requiredExternal, conjunctionType } = queryObj;
|
|
204
151
|
console.log("query :>> ", JSON.stringify(query));
|
|
205
|
-
|
|
152
|
+
let mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
|
|
206
153
|
console.log(":::::::::mongoQuery::::", JSON.stringify(mongoQuery));
|
|
207
|
-
queryConjunctions.push(
|
|
208
|
-
if (
|
|
209
|
-
|
|
154
|
+
queryConjunctions.push(conjunctionType);
|
|
155
|
+
if (conjunctionType == "OR") {
|
|
156
|
+
let lastKey = Object.keys(filterQuery)[Object.keys(filterQuery).length - 1];
|
|
210
157
|
if (filterQuery[lastKey] && Array.isArray(filterQuery[lastKey])) {
|
|
211
158
|
filterQuery[lastKey].push(mongoQuery);
|
|
212
159
|
}
|
|
213
160
|
else {
|
|
214
|
-
filterQuery[
|
|
161
|
+
filterQuery[`$or${index}`] = [mongoQuery];
|
|
215
162
|
}
|
|
216
163
|
}
|
|
217
|
-
else if (
|
|
218
|
-
|
|
164
|
+
else if (conjunctionType == "AND") {
|
|
165
|
+
let lastKey = Object.keys(filterQuery)[Object.keys(filterQuery).length - 1];
|
|
219
166
|
if (filterQuery[lastKey] && Array.isArray(filterQuery[lastKey])) {
|
|
220
167
|
filterQuery[lastKey].push(mongoQuery);
|
|
221
168
|
}
|
|
222
169
|
else {
|
|
223
|
-
filterQuery[
|
|
170
|
+
filterQuery[`$and${index}`] = [mongoQuery];
|
|
224
171
|
}
|
|
225
172
|
}
|
|
226
173
|
else {
|
|
227
|
-
filterQuery[
|
|
174
|
+
filterQuery[`$or${index}`] = [mongoQuery];
|
|
228
175
|
}
|
|
229
176
|
});
|
|
230
177
|
console.log("==> *** filterQuery mongoFilterQuery :>> ", filterQuery);
|
|
231
|
-
|
|
178
|
+
const hasAndQueryConjunction = queryConjunctions.includes("AND");
|
|
232
179
|
return (0, query_utils_1.modifyQuery)(filterQuery, hasAndQueryConjunction);
|
|
233
180
|
};
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (currentUser === void 0) { currentUser = {}; }
|
|
237
|
-
if (currentTenant === void 0) { currentTenant = {}; }
|
|
238
|
-
if (currentUserSetting === void 0) { currentUserSetting = {}; }
|
|
239
|
-
if (currentSubTenant === void 0) { currentSubTenant = {}; }
|
|
240
|
-
var key = query.key, field = query.field, value = query.value, fieldType = query.fieldType;
|
|
181
|
+
const queryToMongo = (query, requiredExternal, externalParams, constants, currentUser = {}, currentTenant = {}, currentUserSetting = {}, currentSubTenant = {}, timezone) => {
|
|
182
|
+
const { key, field, value, fieldType } = query;
|
|
241
183
|
if ([drapcode_constant_1.EQUALS, drapcode_constant_1.NOT_EQUAL, drapcode_constant_1.EQUALS_OR_IGNORE].includes(key) &&
|
|
242
184
|
typeof value === "string" &&
|
|
243
|
-
drapcode_constant_1.DateRangeConstant.some(
|
|
244
|
-
|
|
185
|
+
drapcode_constant_1.DateRangeConstant.some((cnst) => value.includes(cnst))) {
|
|
186
|
+
let final = (0, date_util_1.getDateRangeValue)(key, field, value);
|
|
245
187
|
console.log("\n ===final getDateRangeValue", final);
|
|
246
188
|
return final;
|
|
247
189
|
}
|
|
248
|
-
|
|
190
|
+
let fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
|
|
249
191
|
if (["undefined", "null", null, undefined, ""].includes(fieldValue)) {
|
|
250
192
|
//TODO: In case field is not present in old record then fieldValue is undefined
|
|
251
193
|
//TODO: In case of this, we assign some random string to avoid resulting all values
|
|
252
194
|
//TODO: This is use case in Spot Factor Project, where a new user with blank value able to see all records
|
|
253
195
|
//TODO: Discussed on meet
|
|
254
|
-
fieldValue =
|
|
196
|
+
fieldValue = `random_string_since_field_not_present_${(0, moment_1.default)(1318874398806).valueOf()}`;
|
|
255
197
|
}
|
|
256
198
|
console.log("fieldValue queryToMongo 1", fieldValue);
|
|
257
|
-
|
|
199
|
+
let isDate = (0, query_utils_1.isItDate)(fieldValue);
|
|
258
200
|
console.log("isDate queryToMongo 2", isDate);
|
|
259
201
|
// Todo: Remove if it's working properly
|
|
260
202
|
// if (isDate) fieldValue = new Date(fieldValue);
|
|
261
203
|
console.log("fieldValue queryToMongo 1", fieldValue);
|
|
262
|
-
|
|
204
|
+
let condition = [...drapcode_constant_1.OptionTypeFields, ...drapcode_constant_1.BelongsToReferenceField].includes(fieldType);
|
|
263
205
|
if (condition && key === drapcode_constant_1.EQUALS && !isDate) {
|
|
264
206
|
if (!Array.isArray(fieldValue)) {
|
|
265
207
|
fieldValue = [fieldValue];
|
|
266
208
|
}
|
|
267
|
-
return
|
|
209
|
+
return { [field]: { $in: fieldValue || [] } };
|
|
268
210
|
}
|
|
269
211
|
if (condition && key === drapcode_constant_1.NOT_EQUAL && !isDate) {
|
|
270
212
|
if (!Array.isArray(fieldValue)) {
|
|
271
213
|
fieldValue = [fieldValue];
|
|
272
214
|
}
|
|
273
|
-
return
|
|
215
|
+
return { [field]: { $nin: fieldValue || [] } };
|
|
274
216
|
}
|
|
275
217
|
if (condition && key === drapcode_constant_1.EQUALS_OR_IGNORE && !isDate) {
|
|
276
218
|
if (typeof fieldValue === "string" && fieldValue.startsWith("CURRENT_")) {
|
|
@@ -280,156 +222,163 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
280
222
|
fieldValue = [fieldValue];
|
|
281
223
|
}
|
|
282
224
|
return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
|
|
283
|
-
?
|
|
225
|
+
? { [field]: { $in: fieldValue || [] } }
|
|
226
|
+
: {};
|
|
284
227
|
}
|
|
285
228
|
if (condition && key === drapcode_constant_1.IS_NULL) {
|
|
286
229
|
return {
|
|
287
230
|
$or: [
|
|
288
|
-
|
|
289
|
-
|
|
231
|
+
{ [field]: { $exists: false } },
|
|
232
|
+
{ [field]: { $type: "array", $eq: [] } },
|
|
290
233
|
],
|
|
291
234
|
};
|
|
292
235
|
}
|
|
293
236
|
if (condition && key === drapcode_constant_1.IS_NOT_NULL) {
|
|
294
|
-
return
|
|
237
|
+
return { [field]: { $exists: true, $type: "array", $ne: [] } };
|
|
295
238
|
}
|
|
296
239
|
if (key === drapcode_constant_1.IS_NOT_NULL)
|
|
297
|
-
return
|
|
240
|
+
return { [field]: { $nin: [null, ""] } };
|
|
298
241
|
if (key === drapcode_constant_1.IS_NULL)
|
|
299
|
-
return
|
|
242
|
+
return { [field]: { $in: [null, ""] } };
|
|
300
243
|
if (key === drapcode_constant_1.LIKE)
|
|
301
|
-
return
|
|
244
|
+
return { [field]: { $regex: fieldValue, $options: "i" } };
|
|
302
245
|
if (key === drapcode_constant_1.GREATER_THAN_EQUALS_TO)
|
|
303
|
-
return
|
|
246
|
+
return { [field]: { $gte: isDate ? fieldValue : +fieldValue } };
|
|
304
247
|
if (key === drapcode_constant_1.LESS_THAN_EQUALS_TO)
|
|
305
|
-
return
|
|
248
|
+
return { [field]: { $lte: isDate ? fieldValue : +fieldValue } };
|
|
306
249
|
if (key === drapcode_constant_1.LESS_THAN)
|
|
307
|
-
return
|
|
250
|
+
return { [field]: { $lt: isDate ? fieldValue : +fieldValue } };
|
|
308
251
|
if (key === drapcode_constant_1.GREATER_THAN)
|
|
309
|
-
return
|
|
252
|
+
return { [field]: { $gt: isDate ? fieldValue : +fieldValue } };
|
|
310
253
|
if (key === drapcode_constant_1.IN_LIST) {
|
|
311
254
|
if (!Array.isArray(fieldValue)) {
|
|
312
255
|
fieldValue = [fieldValue];
|
|
313
256
|
}
|
|
314
|
-
return
|
|
257
|
+
return { [field]: { $in: fieldValue || [] } };
|
|
315
258
|
}
|
|
316
259
|
if (key === drapcode_constant_1.NOT_IN_LIST) {
|
|
317
260
|
if (!Array.isArray(fieldValue)) {
|
|
318
261
|
fieldValue = [fieldValue];
|
|
319
262
|
}
|
|
320
|
-
return
|
|
263
|
+
return { [field]: { $nin: fieldValue || [] } };
|
|
321
264
|
}
|
|
322
265
|
if (key === drapcode_constant_1.EQUALS && isDate) {
|
|
323
|
-
return
|
|
324
|
-
|
|
266
|
+
return {
|
|
267
|
+
[field]: {
|
|
325
268
|
$gte: fieldValue,
|
|
326
269
|
$lt: (0, date_util_1.nextDayDate)(fieldValue),
|
|
327
270
|
},
|
|
328
|
-
|
|
271
|
+
};
|
|
329
272
|
}
|
|
330
273
|
if (key === drapcode_constant_1.EQUALS_OR_IGNORE && isDate) {
|
|
331
274
|
return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
|
|
332
|
-
?
|
|
333
|
-
|
|
275
|
+
? {
|
|
276
|
+
[field]: {
|
|
334
277
|
$gte: fieldValue,
|
|
335
278
|
$lt: (0, date_util_1.nextDayDate)(fieldValue),
|
|
336
279
|
},
|
|
337
|
-
|
|
280
|
+
}
|
|
281
|
+
: {};
|
|
338
282
|
}
|
|
339
283
|
if (key == drapcode_constant_1.EQUALS && field === "createdBy")
|
|
340
284
|
return {
|
|
341
285
|
$and: [
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
286
|
+
{ [field]: { $ne: null } },
|
|
287
|
+
{ [field]: { $ne: "" } },
|
|
288
|
+
{ [field]: { $eq: fieldValue } },
|
|
345
289
|
],
|
|
346
290
|
};
|
|
347
291
|
if (key === drapcode_constant_1.EQUALS_OR_IGNORE && field === "createdBy") {
|
|
348
292
|
return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
|
|
349
293
|
? {
|
|
350
294
|
$and: [
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
295
|
+
{ [field]: { $ne: null } },
|
|
296
|
+
{ [field]: { $ne: "" } },
|
|
297
|
+
{ [field]: { $eq: fieldValue } },
|
|
354
298
|
],
|
|
355
299
|
}
|
|
356
300
|
: {};
|
|
357
301
|
}
|
|
358
302
|
if (key == drapcode_constant_1.EQUALS && fieldType === drapcode_constant_1.FieldTypes.boolean.id && fieldValue)
|
|
359
303
|
return JSON.parse(fieldValue)
|
|
360
|
-
?
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
304
|
+
? {
|
|
305
|
+
[field]: JSON.parse(fieldValue),
|
|
306
|
+
}
|
|
307
|
+
: {
|
|
308
|
+
$or: [
|
|
309
|
+
{ [field]: JSON.parse(fieldValue) },
|
|
310
|
+
{ [field]: { $exists: false } },
|
|
311
|
+
],
|
|
312
|
+
};
|
|
368
313
|
if (key === drapcode_constant_1.EQUALS_OR_IGNORE && fieldType === drapcode_constant_1.FieldTypes.boolean.id) {
|
|
369
314
|
return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
|
|
370
315
|
? JSON.parse(fieldValue)
|
|
371
|
-
?
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
316
|
+
? {
|
|
317
|
+
[field]: JSON.parse(fieldValue),
|
|
318
|
+
}
|
|
319
|
+
: {
|
|
320
|
+
$or: [
|
|
321
|
+
{ [field]: JSON.parse(fieldValue) },
|
|
322
|
+
{ [field]: { $exists: false } },
|
|
323
|
+
],
|
|
324
|
+
}
|
|
379
325
|
: {};
|
|
380
326
|
}
|
|
381
327
|
if (key == drapcode_constant_1.EQUALS) {
|
|
382
328
|
console.log("I am query parser");
|
|
383
329
|
console.log("fieldType", fieldType);
|
|
384
330
|
if (fieldType === drapcode_constant_1.FieldTypes.boolean.id) {
|
|
385
|
-
return
|
|
331
|
+
return { [field]: !!fieldValue };
|
|
386
332
|
}
|
|
387
333
|
if (fieldType === drapcode_constant_1.FieldTypes.number.id) {
|
|
388
|
-
return
|
|
334
|
+
return { [field]: +fieldValue };
|
|
389
335
|
}
|
|
390
336
|
console.log("Nothing match");
|
|
391
|
-
return
|
|
337
|
+
return { [field]: `${fieldValue}` };
|
|
392
338
|
}
|
|
393
339
|
if (key === drapcode_constant_1.EQUALS_OR_IGNORE) {
|
|
394
340
|
if (fieldType === drapcode_constant_1.FieldTypes.boolean.id) {
|
|
395
341
|
return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
|
|
396
|
-
?
|
|
342
|
+
? { [field]: !!fieldValue }
|
|
343
|
+
: {};
|
|
397
344
|
}
|
|
398
345
|
if (fieldType === drapcode_constant_1.FieldTypes.number.id) {
|
|
399
346
|
return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
|
|
400
|
-
?
|
|
347
|
+
? { [field]: +fieldValue }
|
|
348
|
+
: {};
|
|
401
349
|
}
|
|
402
350
|
else {
|
|
403
351
|
return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
|
|
404
|
-
?
|
|
352
|
+
? { [field]: fieldValue }
|
|
353
|
+
: {};
|
|
405
354
|
}
|
|
406
355
|
}
|
|
407
356
|
if (key == drapcode_constant_1.NOT_EQUAL)
|
|
408
357
|
if (fieldType === drapcode_constant_1.FieldTypes.number.id) {
|
|
409
|
-
return
|
|
358
|
+
return { [field]: { $ne: +fieldValue } };
|
|
410
359
|
}
|
|
411
360
|
else
|
|
412
|
-
return
|
|
413
|
-
|
|
361
|
+
return {
|
|
362
|
+
[field]: {
|
|
414
363
|
$ne: fieldType === drapcode_constant_1.FieldTypes.boolean.id && fieldValue
|
|
415
364
|
? JSON.parse(fieldValue)
|
|
416
365
|
: fieldValue,
|
|
417
366
|
},
|
|
418
|
-
|
|
367
|
+
};
|
|
419
368
|
if (key == drapcode_constant_1.BETWEEN) {
|
|
420
|
-
|
|
421
|
-
return
|
|
422
|
-
|
|
369
|
+
const { startValue, endValue, isInteger } = (0, query_utils_1.getMinMaxValue)(fieldValue);
|
|
370
|
+
return {
|
|
371
|
+
[field]: {
|
|
423
372
|
$gte: isInteger ? +startValue : startValue,
|
|
424
373
|
$lte: isInteger ? +endValue : endValue,
|
|
425
374
|
},
|
|
426
|
-
|
|
375
|
+
};
|
|
427
376
|
}
|
|
428
377
|
};
|
|
429
|
-
|
|
430
|
-
|
|
378
|
+
const isEntityInCondition = (value) => {
|
|
379
|
+
let isEntity = false;
|
|
431
380
|
if (value && Array.isArray(value)) {
|
|
432
|
-
value.forEach(
|
|
381
|
+
value.forEach((val) => {
|
|
433
382
|
if (typeof val === "string" || val instanceof String)
|
|
434
383
|
isEntity = val.startsWith("ENTITY::");
|
|
435
384
|
});
|
|
@@ -441,13 +390,13 @@ var isEntityInCondition = function (value) {
|
|
|
441
390
|
return isEntity;
|
|
442
391
|
};
|
|
443
392
|
exports.isEntityInCondition = isEntityInCondition;
|
|
444
|
-
|
|
445
|
-
|
|
393
|
+
const replaceExternalParams = (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone) => {
|
|
394
|
+
const { key, value, fieldType } = query;
|
|
446
395
|
if (fieldType &&
|
|
447
396
|
!requiredExternal &&
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
397
|
+
[...drapcode_constant_1.OptionTypeFields, ...drapcode_constant_1.BelongsToReferenceField].includes(fieldType)) {
|
|
398
|
+
const { refCollection, refField } = query;
|
|
399
|
+
let finalValue = "";
|
|
451
400
|
if (drapcode_constant_1.OptionTypeFields.includes(fieldType)) {
|
|
452
401
|
if (!value) {
|
|
453
402
|
if (refCollection === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -476,136 +425,134 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
476
425
|
["true", "false", "", true, false].includes(value)) {
|
|
477
426
|
return "" + value;
|
|
478
427
|
}
|
|
479
|
-
if (
|
|
480
|
-
|
|
428
|
+
if ([drapcode_constant_1.IN_LIST, drapcode_constant_1.NOT_IN_LIST].includes(key)) {
|
|
429
|
+
let valueList = [];
|
|
481
430
|
if (value && Array.isArray(value)) {
|
|
482
|
-
value.forEach(
|
|
483
|
-
constants.forEach(
|
|
484
|
-
value.forEach(
|
|
431
|
+
value.forEach((val) => valueList.push(val));
|
|
432
|
+
constants.forEach((constant) => {
|
|
433
|
+
value.forEach((val) => {
|
|
485
434
|
if (val === constant.name)
|
|
486
|
-
|
|
435
|
+
valueList.push(constant.value);
|
|
487
436
|
});
|
|
488
437
|
});
|
|
489
438
|
}
|
|
490
439
|
else {
|
|
491
|
-
|
|
440
|
+
const constantDataObj = [
|
|
492
441
|
{ constantName: drapcode_constant_1.CURRENT_USER, data: currentUser },
|
|
493
442
|
{ constantName: drapcode_constant_1.CURRENT_TENANT, data: currentTenant },
|
|
494
443
|
{ constantName: drapcode_constant_1.CURRENT_SETTINGS, data: currentUserSetting },
|
|
495
444
|
{ constantName: drapcode_constant_1.CURRENT_SUB_TENANT, data: currentSubTenant },
|
|
496
445
|
];
|
|
497
|
-
constantDataObj.forEach(
|
|
446
|
+
constantDataObj.forEach((cnst) => {
|
|
498
447
|
if (value.includes(cnst.constantName)) {
|
|
499
|
-
|
|
448
|
+
const currentDataValue = getCurrentDataValueFrom(value, cnst.constantName, cnst.data, true);
|
|
500
449
|
if (currentDataValue) {
|
|
501
|
-
|
|
502
|
-
?
|
|
450
|
+
valueList = Array.isArray(currentDataValue)
|
|
451
|
+
? [...valueList, ...currentDataValue]
|
|
452
|
+
: [...valueList, currentDataValue];
|
|
503
453
|
}
|
|
504
454
|
}
|
|
505
455
|
});
|
|
506
456
|
}
|
|
507
|
-
return
|
|
457
|
+
return valueList;
|
|
508
458
|
}
|
|
509
459
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
510
|
-
|
|
460
|
+
let { startValue, endValue, isFixedValue } = (0, query_utils_1.getMinMaxValue)(value);
|
|
511
461
|
if (requiredExternal) {
|
|
512
|
-
|
|
513
|
-
|
|
462
|
+
startValue = `${externalParams[startValue]}`;
|
|
463
|
+
endValue = `${externalParams[endValue]}`;
|
|
514
464
|
}
|
|
515
465
|
else {
|
|
516
|
-
if (
|
|
517
|
-
|
|
518
|
-
})) {
|
|
519
|
-
startValue_1 = (0, query_utils_1.getValueOfProjectConstant)(startValue_1, currentUser, timezone);
|
|
466
|
+
if ([drapcode_constant_1.CURRENT_USER, ...drapcode_constant_1.DateConstant].some((cnst) => startValue.includes(cnst))) {
|
|
467
|
+
startValue = (0, query_utils_1.getValueOfProjectConstant)(startValue, currentUser, timezone);
|
|
520
468
|
}
|
|
521
469
|
else if (!isFixedValue) {
|
|
522
|
-
|
|
470
|
+
startValue = constants.filter((constant) => constant.name == startValue);
|
|
523
471
|
}
|
|
524
|
-
if (
|
|
525
|
-
|
|
472
|
+
if ([drapcode_constant_1.CURRENT_USER, ...drapcode_constant_1.DateConstant].some((cnst) => endValue.includes(cnst))) {
|
|
473
|
+
endValue = (0, query_utils_1.getValueOfProjectConstant)(endValue, currentUser, timezone);
|
|
526
474
|
}
|
|
527
475
|
else if (!isFixedValue) {
|
|
528
|
-
|
|
476
|
+
endValue = constants.filter((constant) => constant.name == endValue);
|
|
529
477
|
}
|
|
530
478
|
}
|
|
531
|
-
if (Array.isArray(
|
|
532
|
-
|
|
479
|
+
if (Array.isArray(startValue)) {
|
|
480
|
+
startValue = startValue[0].value;
|
|
533
481
|
}
|
|
534
|
-
if (Array.isArray(
|
|
535
|
-
|
|
482
|
+
if (Array.isArray(endValue)) {
|
|
483
|
+
endValue = endValue[0].value;
|
|
536
484
|
}
|
|
537
|
-
if (!isNaN(
|
|
538
|
-
return
|
|
485
|
+
if (!isNaN(startValue)) {
|
|
486
|
+
return `${startValue}---${endValue}^`;
|
|
539
487
|
}
|
|
540
488
|
else
|
|
541
|
-
return
|
|
489
|
+
return `${startValue}---${endValue}`;
|
|
542
490
|
}
|
|
543
|
-
|
|
491
|
+
const currentUserValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_USER, currentUser);
|
|
544
492
|
console.log("\n currentUserValue :>> ", currentUserValue);
|
|
545
493
|
if (currentUserValue)
|
|
546
494
|
return currentUserValue;
|
|
547
|
-
|
|
495
|
+
const currentTenantValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_TENANT, currentTenant);
|
|
548
496
|
console.log("\n currentTenantValue :>> ", currentTenantValue);
|
|
549
497
|
if (currentTenantValue)
|
|
550
498
|
return currentTenantValue;
|
|
551
|
-
|
|
499
|
+
const currentUserSettingsValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_SETTINGS, currentUserSetting);
|
|
552
500
|
console.log("\n currentUserSettingsValue :>> ", currentUserSettingsValue);
|
|
553
501
|
if (currentUserSettingsValue)
|
|
554
502
|
return currentUserSettingsValue;
|
|
555
|
-
|
|
503
|
+
const currentSubTenantValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_SUB_TENANT, currentSubTenant);
|
|
556
504
|
if (currentSubTenantValue)
|
|
557
505
|
return currentSubTenantValue;
|
|
558
|
-
if (drapcode_constant_1.DateConstant.some(
|
|
506
|
+
if (drapcode_constant_1.DateConstant.some((cnst) => value.includes(cnst))) {
|
|
559
507
|
return (0, query_utils_1.getValueOfProjectConstant)(value, {}, timezone);
|
|
560
508
|
}
|
|
561
509
|
if ((0, exports.isEntityInCondition)(value)) {
|
|
562
|
-
|
|
563
|
-
return externalParams[
|
|
510
|
+
const key = value.replace("ENTITY::", "");
|
|
511
|
+
return externalParams[key] ? externalParams[key] : "";
|
|
564
512
|
}
|
|
565
513
|
if ((0, query_utils_1.isFixedValueQuery)(value))
|
|
566
514
|
return value.replace("FIXED_VALUE::", "");
|
|
567
515
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
568
516
|
if (requiredExternal) {
|
|
569
517
|
//TODO: Value returns from here undefined.
|
|
570
|
-
|
|
518
|
+
let externalParamValue = externalParams[`${value}`];
|
|
571
519
|
if (!isNaN(externalParamValue)) {
|
|
572
520
|
return +externalParamValue;
|
|
573
521
|
}
|
|
574
|
-
return externalParams[
|
|
522
|
+
return externalParams[`${value}`];
|
|
575
523
|
}
|
|
576
|
-
|
|
524
|
+
let constantArr = constants.filter((constant) => constant.name == value);
|
|
577
525
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
578
526
|
};
|
|
579
|
-
|
|
580
|
-
if (isMultiRef === void 0) { isMultiRef = false; }
|
|
527
|
+
const getCurrentDataValueFrom = (value, constantName, data, isMultiRef = false) => {
|
|
581
528
|
if (value.includes(constantName)) {
|
|
582
529
|
if (value === constantName)
|
|
583
|
-
return data[
|
|
584
|
-
|
|
530
|
+
return data[`uuid`];
|
|
531
|
+
const splitValues = value.split("::");
|
|
585
532
|
console.log("splitValues", splitValues);
|
|
586
|
-
|
|
533
|
+
let refCollection = "", refCollectionField = "";
|
|
587
534
|
if (splitValues.length > 2) {
|
|
588
535
|
refCollection = splitValues[1];
|
|
589
|
-
|
|
536
|
+
refCollectionField = splitValues[2];
|
|
590
537
|
}
|
|
591
538
|
else if (splitValues.length === 2) {
|
|
592
539
|
refCollection = splitValues[0];
|
|
593
|
-
|
|
540
|
+
refCollectionField = splitValues[1];
|
|
594
541
|
}
|
|
595
542
|
else {
|
|
596
543
|
refCollection = splitValues[0];
|
|
597
|
-
|
|
544
|
+
refCollectionField = "";
|
|
598
545
|
}
|
|
599
546
|
console.log("refCollection", refCollection);
|
|
600
|
-
console.log("refCollectionField",
|
|
601
|
-
console.log("first",
|
|
602
|
-
if (refCollection &&
|
|
547
|
+
console.log("refCollectionField", refCollectionField);
|
|
548
|
+
console.log("first", refCollectionField && refCollection);
|
|
549
|
+
if (refCollection && refCollectionField) {
|
|
603
550
|
console.log("I have refCollection and Field");
|
|
604
551
|
if (refCollection === constantName) {
|
|
605
|
-
return data[
|
|
552
|
+
return data[refCollectionField];
|
|
606
553
|
}
|
|
607
554
|
else {
|
|
608
|
-
|
|
555
|
+
let refCollectionData = data[refCollection];
|
|
609
556
|
console.log("refCollectionData", refCollectionData);
|
|
610
557
|
if (!refCollectionData)
|
|
611
558
|
return "";
|
|
@@ -614,21 +561,21 @@ var getCurrentDataValueFrom = function (value, constantName, data, isMultiRef) {
|
|
|
614
561
|
// Handled For IN_LIST and NOT_IN_LIST Condition
|
|
615
562
|
if (!isMultiRef)
|
|
616
563
|
return "";
|
|
617
|
-
|
|
618
|
-
refCollectionData.forEach(
|
|
619
|
-
if (refData[
|
|
620
|
-
|
|
564
|
+
let finalValue = [];
|
|
565
|
+
refCollectionData.forEach((refData) => {
|
|
566
|
+
if (refData[refCollectionField])
|
|
567
|
+
finalValue.push(refData[refCollectionField]);
|
|
621
568
|
});
|
|
622
|
-
return
|
|
569
|
+
return finalValue;
|
|
623
570
|
}
|
|
624
571
|
refCollectionData = refCollectionData[0];
|
|
625
|
-
console.log(
|
|
626
|
-
return refCollectionData[
|
|
572
|
+
console.log(`refCollectionData[refCollectionField]`, refCollectionData[refCollectionField]);
|
|
573
|
+
return refCollectionData[refCollectionField];
|
|
627
574
|
}
|
|
628
575
|
}
|
|
629
576
|
//this means that data has to be match with currnet user field that is not ref type
|
|
630
577
|
if (refCollection)
|
|
631
578
|
return data[refCollection];
|
|
632
|
-
return data[
|
|
579
|
+
return data[`uuid`];
|
|
633
580
|
}
|
|
634
581
|
};
|