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.
Files changed (50) hide show
  1. package/build/encryption/KMS.js +54 -102
  2. package/build/encryption/crypt.d.ts +4 -2
  3. package/build/encryption/crypt.js +76 -91
  4. package/build/encryption/file.d.ts +0 -2
  5. package/build/encryption/file.js +14 -130
  6. package/build/encryption/index.js +162 -334
  7. package/build/encryption/utility.js +7 -10
  8. package/build/errors/app-error.js +9 -27
  9. package/build/errors/axios-error.js +3 -3
  10. package/build/errors/bad-request-error.js +10 -28
  11. package/build/errors/custom-error.js +5 -23
  12. package/build/errors/not-found.js +9 -27
  13. package/build/format-fields/index.d.ts +0 -1
  14. package/build/format-fields/index.js +32 -65
  15. package/build/index.d.ts +1 -4
  16. package/build/index.js +1 -4
  17. package/build/middlewares/error-logger.d.ts +1 -1
  18. package/build/middlewares/error-logger.js +29 -29
  19. package/build/middlewares/redis/request-log.js +24 -74
  20. package/build/query/queryBuilder.d.ts +9 -0
  21. package/build/query/queryBuilder.js +567 -0
  22. package/build/utils/check-error.d.ts +15 -8
  23. package/build/utils/check-error.js +71 -160
  24. package/build/utils/common-util.d.ts +40 -39
  25. package/build/utils/common-util.js +60 -59
  26. package/build/utils/date-util.d.ts +28 -7
  27. package/build/utils/date-util.js +180 -127
  28. package/build/utils/file-util.d.ts +51 -6
  29. package/build/utils/file-util.js +36 -40
  30. package/build/utils/prepare-query.js +70 -43
  31. package/build/utils/project-util.d.ts +43 -5
  32. package/build/utils/project-util.js +176 -121
  33. package/build/utils/query-parser.d.ts +1 -1
  34. package/build/utils/query-parser.js +289 -342
  35. package/build/utils/query-utils.d.ts +2 -2
  36. package/build/utils/query-utils.js +103 -116
  37. package/build/utils/rest-client.js +236 -328
  38. package/build/utils/s3-util.js +238 -469
  39. package/build/utils/token.js +34 -81
  40. package/build/utils/util.d.ts +58 -13
  41. package/build/utils/util.js +424 -494
  42. package/build/utils/uuid-generator.d.ts +20 -1
  43. package/build/utils/uuid-generator.js +111 -47
  44. package/package.json +7 -5
  45. package/build/middlewares/interceptor-logger-new.d.ts +0 -2
  46. package/build/middlewares/interceptor-logger-new.js +0 -53
  47. package/build/middlewares/interceptor-logger.d.ts +0 -2
  48. package/build/middlewares/interceptor-logger.js +0 -52
  49. package/build/utils/query-parser-new.d.ts +0 -1
  50. package/build/utils/query-parser-new.js +0 -541
@@ -1,541 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.queryParserNew = void 0;
49
- var drapcode_constant_1 = require("drapcode-constant");
50
- var date_util_1 = require("./date-util");
51
- var util_1 = require("./util");
52
- var prepare_query_1 = require("./prepare-query");
53
- var query_utils_1 = require("./query-utils");
54
- var queryParserNew = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, lookupConfig) {
55
- if (currentUser === void 0) { currentUser = {}; }
56
- if (searchObj === void 0) { searchObj = null; }
57
- if (refCollectionFieldsInItems === void 0) { refCollectionFieldsInItems = null; }
58
- if (searchQueryTypeObj === void 0) { searchQueryTypeObj = {}; }
59
- if (lookupConfig === void 0) { lookupConfig = []; }
60
- return __awaiter(void 0, void 0, void 0, function () {
61
- var filterQuery, aggregateQuery, queryStr, searchQueryObj_1, finalQuery, _a, searchAggregateQuery, likeQuery, projection, finder, sortBy, orderBy, aggregateFunctionField, offset, limit, direction;
62
- var _b;
63
- return __generator(this, function (_c) {
64
- switch (_c.label) {
65
- case 0:
66
- if (!collectionName)
67
- return [2 /*return*/, ""];
68
- if (!query)
69
- return [2 /*return*/, ""];
70
- console.log("***1*** queryParserNew ***");
71
- filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser);
72
- console.log("**************************");
73
- console.log("**************************");
74
- console.log("filterQuery", JSON.stringify(filterQuery));
75
- console.log("==> searchQueryTypeObj :>>", searchQueryTypeObj);
76
- aggregateQuery = [];
77
- queryStr = ".aggregate([])";
78
- if (filterQuery.length &&
79
- ((filterQuery[0].$or && filterQuery[0].$or.length) ||
80
- (filterQuery[0].$and && filterQuery[0].$and.length))) {
81
- searchQueryObj_1 = null;
82
- if (searchObj) {
83
- searchQueryObj_1 = [];
84
- Object.entries(searchObj).forEach(function (_a) {
85
- var _b, _c, _d;
86
- var key = _a[0], value = _a[1];
87
- if (value) {
88
- if (searchQueryTypeObj[key]) {
89
- aggregateQuery.push({
90
- $addFields: (_b = {},
91
- _b["_".concat(key)] = { $toString: "$".concat(key) },
92
- _b),
93
- });
94
- searchQueryObj_1.push((_c = {},
95
- _c["_".concat(key)] = {
96
- $regex: value,
97
- $options: "i",
98
- },
99
- _c));
100
- }
101
- else {
102
- searchQueryObj_1.push((_d = {},
103
- _d[key] = {
104
- $regex: value,
105
- $options: "i",
106
- },
107
- _d));
108
- }
109
- }
110
- });
111
- }
112
- finalQuery = { $and: filterQuery };
113
- if (searchQueryObj_1.length) {
114
- finalQuery.$and.push([searchQueryObj_1]);
115
- }
116
- aggregateQuery.push({ $match: finalQuery });
117
- }
118
- else if (searchObj) {
119
- _a = (0, query_utils_1.getSearchObjQuery)(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
120
- aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery, true), searchAggregateQuery, true);
121
- if (likeQuery.length) {
122
- aggregateQuery.push({ $match: { $and: likeQuery } });
123
- }
124
- }
125
- console.log("==> query", query);
126
- projection = (0, query_utils_1.mongoSelectQuery)(query);
127
- finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy, aggregateFunctionField = query.aggregateFunctionField;
128
- if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
129
- return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
130
- return (0, prepare_query_1.commonLookupSetting)(field, lookupConfig, aggregateQuery);
131
- }))];
132
- case 1:
133
- _c.sent();
134
- _c.label = 2;
135
- case 2:
136
- if (!["COUNT", "SUM", "AVG", "MIN", "MAX"].includes(finder) &&
137
- !(0, util_1.isEmpty)(projection)) {
138
- aggregateQuery.push({ $project: projection });
139
- }
140
- if (finder === "COUNT") {
141
- aggregateQuery.push({ $group: { _id: null, count: { $sum: 1 } } });
142
- }
143
- else if (finder === "SUM") {
144
- aggregateQuery.push({
145
- $group: { _id: null, total: { $sum: "$".concat(aggregateFunctionField) } },
146
- });
147
- }
148
- else if (finder === "AVG") {
149
- aggregateQuery.push({
150
- $group: { _id: null, average: { $avg: "$".concat(aggregateFunctionField) } },
151
- });
152
- }
153
- else if (finder === "MIN") {
154
- aggregateQuery.push({
155
- $group: { _id: null, minimum: { $min: "$".concat(aggregateFunctionField) } },
156
- });
157
- }
158
- else if (finder === "MAX") {
159
- aggregateQuery.push({
160
- $group: { _id: null, maximum: { $max: "$".concat(aggregateFunctionField) } },
161
- });
162
- }
163
- offset = externalParams.offset || 0;
164
- limit = externalParams.limit || 10;
165
- if (externalParams.pagination == "false") {
166
- limit = 0;
167
- sortBy = 0;
168
- }
169
- if (finder != "COUNT" && sortBy) {
170
- direction = orderBy && orderBy == "asc" ? 1 : -1;
171
- aggregateQuery.push({ $sort: (_b = {}, _b[sortBy] = direction, _b) });
172
- }
173
- if (finder != "COUNT" && limit) {
174
- aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
175
- }
176
- console.log("==> aggregateQuery", JSON.stringify(aggregateQuery, null, 2));
177
- return [2 /*return*/, aggregateQuery];
178
- }
179
- });
180
- });
181
- };
182
- exports.queryParserNew = queryParserNew;
183
- var toBoolean = function (value) {
184
- if (!value) {
185
- return false;
186
- }
187
- switch (value.toLocaleLowerCase()) {
188
- case "true":
189
- case "1":
190
- case "on":
191
- case "yes":
192
- return true;
193
- default:
194
- return false;
195
- }
196
- };
197
- var mongoFilterQuery = function (query, externalParams, constants, currentUser) {
198
- if (currentUser === void 0) { currentUser = {}; }
199
- var filterQuery = { $or0: [] };
200
- var conditions = query.conditions;
201
- var queryConjunctions = [];
202
- conditions.forEach(function (queryObj, index) {
203
- var query = queryObj.query, requiredExternal = queryObj.requiredExternal;
204
- var mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser);
205
- queryConjunctions.push(queryObj.conjunctionType);
206
- if (queryObj.conjunctionType == "OR") {
207
- var lastKey = Object.keys(filterQuery)[Object.keys(filterQuery).length - 1];
208
- if (filterQuery[lastKey] && Array.isArray(filterQuery[lastKey])) {
209
- filterQuery[lastKey].push(mongoQuery);
210
- }
211
- else {
212
- filterQuery["$or".concat(index)] = [mongoQuery];
213
- }
214
- }
215
- else if (queryObj.conjunctionType == "AND") {
216
- var lastKey = Object.keys(filterQuery)[Object.keys(filterQuery).length - 1];
217
- if (filterQuery[lastKey] && Array.isArray(filterQuery[lastKey])) {
218
- filterQuery[lastKey].push(mongoQuery);
219
- }
220
- else {
221
- filterQuery["$and".concat(index)] = [mongoQuery];
222
- }
223
- }
224
- else {
225
- filterQuery["$or".concat(index)] = [mongoQuery];
226
- }
227
- });
228
- console.log("==> *** filterQuery #2 :>> ", filterQuery);
229
- var hasAndQueryConjunction = queryConjunctions.includes("AND");
230
- return (0, query_utils_1.modifyQuery)(filterQuery, hasAndQueryConjunction);
231
- };
232
- var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser) {
233
- 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, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
234
- if (currentUser === void 0) { currentUser = {}; }
235
- var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser);
236
- var isDate = (0, query_utils_1.checkDate)(fieldValue);
237
- var key = query.key, field = query.field, value = query.value, fieldType = query.fieldType;
238
- if (isDate)
239
- fieldValue = new Date(fieldValue);
240
- var condition = drapcode_constant_1.SelectOptionFields.includes(fieldType);
241
- if (condition && key === drapcode_constant_1.EQUALS && !isDate) {
242
- if (!Array.isArray(fieldValue)) {
243
- fieldValue = [fieldValue];
244
- }
245
- return _a = {}, _a[field] = { $in: fieldValue || [] }, _a;
246
- }
247
- if (condition && key === drapcode_constant_1.NOT_EQUAL && !isDate) {
248
- if (!Array.isArray(fieldValue)) {
249
- fieldValue = [fieldValue];
250
- }
251
- return _b = {}, _b[field] = { $nin: fieldValue || [] }, _b;
252
- }
253
- if (condition && key === drapcode_constant_1.EQUALS_OR_IGNORE && !isDate) {
254
- if (typeof fieldValue === "string" && fieldValue.startsWith("CURRENT_")) {
255
- fieldValue = "random_string_since_field_not_present_1318874398806";
256
- } //Doing this because when Current Logged In Tenant/Settings/User have no data in that specific field then they return the fieldValue as CURRENT_SETTINGS:field not blank
257
- if (!Array.isArray(fieldValue)) {
258
- fieldValue = [fieldValue];
259
- }
260
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
261
- ? (_c = {}, _c[field] = { $in: fieldValue || [] }, _c) : {};
262
- }
263
- if (condition && key === drapcode_constant_1.IS_NULL) {
264
- return {
265
- $or: [
266
- (_d = {}, _d[field] = { $exists: false }, _d),
267
- (_e = {}, _e[field] = { $type: "array", $eq: [] }, _e),
268
- ],
269
- };
270
- }
271
- if (condition && key === drapcode_constant_1.IS_NOT_NULL) {
272
- return _f = {}, _f[field] = { $exists: true, $type: "array", $ne: [] }, _f;
273
- }
274
- if (key === drapcode_constant_1.IS_NOT_NULL)
275
- return _g = {}, _g[field] = { $nin: [null, ""] }, _g;
276
- if (key === drapcode_constant_1.IS_NULL)
277
- return _h = {}, _h[field] = { $in: [null, ""] }, _h;
278
- if (key === drapcode_constant_1.LIKE)
279
- return _j = {}, _j[field] = { $regex: fieldValue, $options: "i" }, _j;
280
- if (key === drapcode_constant_1.GREATER_THAN_EQUALS_TO)
281
- return _k = {}, _k[field] = { $gte: isDate ? fieldValue : +fieldValue }, _k;
282
- if (key === drapcode_constant_1.LESS_THAN_EQUALS_TO)
283
- return _l = {}, _l[field] = { $lte: isDate ? fieldValue : +fieldValue }, _l;
284
- if (key === drapcode_constant_1.LESS_THAN)
285
- return _m = {}, _m[field] = { $lt: isDate ? fieldValue : +fieldValue }, _m;
286
- if (key === drapcode_constant_1.GREATER_THAN)
287
- return _o = {}, _o[field] = { $gt: isDate ? fieldValue : +fieldValue }, _o;
288
- if (key === drapcode_constant_1.IN_LIST) {
289
- if (!Array.isArray(fieldValue)) {
290
- fieldValue = [fieldValue];
291
- }
292
- return _p = {}, _p[field] = { $in: fieldValue || [] }, _p;
293
- }
294
- if (key === drapcode_constant_1.NOT_IN_LIST) {
295
- if (!Array.isArray(fieldValue)) {
296
- fieldValue = [fieldValue];
297
- }
298
- return _q = {}, _q[field] = { $nin: fieldValue || [] }, _q;
299
- }
300
- if (key === drapcode_constant_1.EQUALS && isDate) {
301
- if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); }))
302
- return _r = {},
303
- _r[field] = {
304
- $gte: fieldValue,
305
- },
306
- _r;
307
- else
308
- return _s = {},
309
- _s[field] = {
310
- $gte: fieldValue,
311
- $lt: new Date((0, date_util_1.nextDayDate)(fieldValue)),
312
- },
313
- _s;
314
- }
315
- if (key === drapcode_constant_1.EQUALS_OR_IGNORE && isDate) {
316
- if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); }))
317
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
318
- ? (_t = {},
319
- _t[field] = {
320
- $gte: fieldValue,
321
- },
322
- _t) : {};
323
- else
324
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
325
- ? (_u = {},
326
- _u[field] = {
327
- $gte: fieldValue,
328
- $lt: new Date((0, date_util_1.nextDayDate)(fieldValue)),
329
- },
330
- _u) : {};
331
- }
332
- if (key == drapcode_constant_1.EQUALS && field === "createdBy")
333
- return {
334
- $and: [
335
- (_v = {}, _v[field] = { $ne: null }, _v),
336
- (_w = {}, _w[field] = { $ne: "" }, _w),
337
- (_x = {}, _x[field] = { $eq: fieldValue }, _x),
338
- ],
339
- };
340
- if (key === drapcode_constant_1.EQUALS_OR_IGNORE && field === "createdBy") {
341
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
342
- ? {
343
- $and: [
344
- (_y = {}, _y[field] = { $ne: null }, _y),
345
- (_z = {}, _z[field] = { $ne: "" }, _z),
346
- (_0 = {}, _0[field] = { $eq: fieldValue }, _0),
347
- ],
348
- }
349
- : {};
350
- }
351
- if (key == drapcode_constant_1.EQUALS && fieldType === "boolean" && fieldValue)
352
- return JSON.parse(fieldValue)
353
- ? (_1 = {},
354
- _1[field] = JSON.parse(fieldValue),
355
- _1) : {
356
- $or: [
357
- (_2 = {}, _2[field] = JSON.parse(fieldValue), _2),
358
- (_3 = {}, _3[field] = { $exists: false }, _3),
359
- ],
360
- };
361
- if (key === drapcode_constant_1.EQUALS_OR_IGNORE && fieldType === "boolean") {
362
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
363
- ? JSON.parse(fieldValue)
364
- ? (_4 = {},
365
- _4[field] = JSON.parse(fieldValue),
366
- _4) : {
367
- $or: [
368
- (_5 = {}, _5[field] = JSON.parse(fieldValue), _5),
369
- (_6 = {}, _6[field] = { $exists: false }, _6),
370
- ],
371
- }
372
- : {};
373
- }
374
- if (key == drapcode_constant_1.EQUALS) {
375
- console.log("I am query parser new");
376
- if (fieldType === "boolean") {
377
- return _7 = {}, _7[field] = !!fieldValue, _7;
378
- }
379
- if (fieldType === "number") {
380
- return _8 = {}, _8[field] = +fieldValue, _8;
381
- }
382
- console.log("Nothing match");
383
- return _9 = {}, _9[field] = "".concat(fieldValue), _9;
384
- }
385
- if (key === drapcode_constant_1.EQUALS_OR_IGNORE) {
386
- if (fieldType === "boolean") {
387
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
388
- ? (_10 = {}, _10[field] = !!fieldValue, _10) : {};
389
- }
390
- if (fieldType === "number") {
391
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
392
- ? (_11 = {}, _11[field] = +fieldValue, _11) : {};
393
- }
394
- else {
395
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
396
- ? (_12 = {}, _12[field] = fieldValue, _12) : {};
397
- }
398
- }
399
- if (key == drapcode_constant_1.NOT_EQUAL)
400
- return _13 = {},
401
- _13[field] = {
402
- $ne: fieldType === "boolean" && fieldValue
403
- ? JSON.parse(fieldValue)
404
- : fieldValue,
405
- },
406
- _13;
407
- if (key == drapcode_constant_1.BETWEEN) {
408
- var _15 = (0, query_utils_1.getMinMaxValue)(fieldValue), startValue = _15.startValue, endValue = _15.endValue, isInteger = _15.isInteger;
409
- return _14 = {},
410
- _14[field] = {
411
- $gte: isInteger ? +startValue : startValue,
412
- $lte: isInteger ? +endValue : endValue,
413
- },
414
- _14;
415
- }
416
- };
417
- var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser) {
418
- var key = query.key, value = query.value, fieldType = query.fieldType;
419
- if (fieldType &&
420
- !requiredExternal &&
421
- drapcode_constant_1.SelectOptionFields.includes(fieldType)) {
422
- //Todo: Remove if filter is working properly
423
- // return value === CURRENT_USER ? currentUser["uuid"] : value;
424
- var refCollection = query.refCollection, refField = query.refField;
425
- var finalValue = "";
426
- if (drapcode_constant_1.OptionTypeFields.includes(fieldType)) {
427
- if (!value) {
428
- if (refCollection === drapcode_constant_1.CURRENT_USER) {
429
- finalValue = currentUser[refField];
430
- }
431
- }
432
- }
433
- if (value === drapcode_constant_1.CURRENT_USER) {
434
- finalValue = currentUser["uuid"];
435
- }
436
- if (!finalValue)
437
- finalValue = value;
438
- return finalValue;
439
- }
440
- if (fieldType &&
441
- fieldType === "boolean" &&
442
- ["true", "false", "", true, false].includes(value)) {
443
- return "" + value;
444
- }
445
- if (key === drapcode_constant_1.IN_LIST || key === drapcode_constant_1.NOT_IN_LIST) {
446
- var valueList_1 = [];
447
- constants.forEach(function (constant) {
448
- if (value && Array.isArray(value)) {
449
- value.forEach(function (val) {
450
- if (val === constant.name) {
451
- valueList_1.push(constant.value);
452
- }
453
- else
454
- valueList_1.push(val);
455
- });
456
- }
457
- });
458
- return valueList_1;
459
- }
460
- if (key === drapcode_constant_1.BETWEEN) {
461
- var _a = (0, query_utils_1.getMinMaxValue)(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
462
- if (requiredExternal) {
463
- startValue_1 = "".concat(externalParams[startValue_1]);
464
- endValue_1 = "".concat(externalParams[endValue_1]);
465
- }
466
- else {
467
- if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) {
468
- return startValue_1.includes(cnst);
469
- })) {
470
- startValue_1 = (0, query_utils_1.getValueOfProjectConstant)(startValue_1, currentUser, "");
471
- }
472
- else {
473
- startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
474
- }
475
- if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) { return endValue_1.includes(cnst); })) {
476
- endValue_1 = (0, query_utils_1.getValueOfProjectConstant)(endValue_1, currentUser, "");
477
- }
478
- else {
479
- endValue_1 = constants.filter(function (constant) { return constant.name == endValue_1; });
480
- }
481
- }
482
- //TODO: Need to test constant from collection and when this below if will run
483
- if (Array.isArray(startValue_1)) {
484
- startValue_1 = startValue_1[0].value;
485
- }
486
- if (Array.isArray(endValue_1)) {
487
- endValue_1 = endValue_1[0].value;
488
- }
489
- //TODO: Need to figure out the params should be treated as number/string
490
- if (!isNaN(startValue_1)) {
491
- console.log("I am Number");
492
- return "".concat(startValue_1, "---").concat(endValue_1, "^");
493
- }
494
- else
495
- return "".concat(startValue_1, "---").concat(endValue_1);
496
- }
497
- if (value.includes(drapcode_constant_1.CURRENT_USER)) {
498
- if (value === drapcode_constant_1.CURRENT_USER) {
499
- return currentUser["uuid"];
500
- }
501
- var splitValues = value.split("::");
502
- var refCollection = splitValues[1];
503
- var refCollectionField = splitValues[2];
504
- if (refCollection && refCollectionField) {
505
- console.log("I have refCollection and Field");
506
- var refCollectionData = currentUser[refCollection];
507
- if (!refCollectionData) {
508
- return "";
509
- }
510
- if (refCollectionData.length > 1) {
511
- //TODO: Need to handle multi ref
512
- return "";
513
- }
514
- refCollectionData = refCollectionData[0];
515
- console.log("refCollectionData[refCollectionField]", refCollectionData[refCollectionField]);
516
- return refCollectionData[refCollectionField];
517
- }
518
- //this means that data has to be match with currnet user field that is not ref type
519
- if (refCollection) {
520
- return currentUser[refCollection];
521
- }
522
- return currentUser["uuid"];
523
- }
524
- if (value === drapcode_constant_1.CURRENT_USER) {
525
- return currentUser["uuid"];
526
- }
527
- if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
528
- return (0, query_utils_1.getValueOfProjectConstant)(value, {}, "");
529
- }
530
- //TODO: This is just to confirm if external then it should be get from externalParams
531
- if (requiredExternal) {
532
- //TODO: Value returns from here undefined.
533
- var externalParamValue = externalParams["".concat(value)];
534
- if (!isNaN(externalParamValue)) {
535
- return +externalParamValue;
536
- }
537
- return externalParams["".concat(value)];
538
- }
539
- var constantArr = constants.filter(function (constant) { return constant.name == value; });
540
- return constantArr.length ? "" + constantArr[0].value : "";
541
- };