drapcode-utility 1.1.1 → 1.1.3
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/index.d.ts +2 -2
- package/build/encryption/index.js +2 -2
- package/build/errors/app-error.js +2 -0
- package/build/errors/bad-request-error.js +2 -0
- package/build/errors/custom-error.js +2 -0
- package/build/errors/not-found.js +2 -0
- package/build/index.js +5 -1
- package/build/middlewares/api-limiter.js +1 -1
- package/build/middlewares/error-logger.js +6 -6
- package/build/middlewares/interceptor-logger-new.js +7 -7
- package/build/middlewares/interceptor-logger.js +4 -4
- package/build/middlewares/redis/request-log.js +4 -4
- package/build/utils/check-error.js +12 -10
- package/build/utils/date-util.js +3 -3
- package/build/utils/query-parser.js +57 -55
- package/build/utils/query-paser-new.js +52 -50
- package/build/utils/util.d.ts +1 -1
- package/build/utils/util.js +11 -11
- package/build/utils/uuid-generator.js +2 -2
- package/package.json +4 -4
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -58,7 +58,7 @@ var crypt = function (data, fields, encryption, decrypt) { return __awaiter(void
|
|
|
58
58
|
secretAccessKey: secretAccessKey,
|
|
59
59
|
},
|
|
60
60
|
};
|
|
61
|
-
return [4 /*yield*/, exports.decryptDataKey(encryption.key, config)];
|
|
61
|
+
return [4 /*yield*/, (0, exports.decryptDataKey)(encryption.key, config)];
|
|
62
62
|
case 1:
|
|
63
63
|
key = _b.sent();
|
|
64
64
|
encryption.key = key.toString("base64");
|
|
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
9
|
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
9
|
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
9
|
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
9
|
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,7 +14,7 @@ exports.apiLimiter = rateLimit({
|
|
|
14
14
|
req.socket.remoteAddress ||
|
|
15
15
|
(req.connection.socket ? req.connection.socket.remoteAddress : null);
|
|
16
16
|
var key = Array.isArray(subdomains) && subdomains.length
|
|
17
|
-
? ip
|
|
17
|
+
? "".concat(ip, "-").concat(subdomains[1])
|
|
18
18
|
: ip;
|
|
19
19
|
return key;
|
|
20
20
|
},
|
|
@@ -32,16 +32,16 @@ var errorLogger = function (err, req, res, next) {
|
|
|
32
32
|
var originalUrl = req.originalUrl, method = req.method, body = req.body, params = req.params, query = req.query, db = req.db, projectName = req.projectName, projectId = req.projectId, ip = req.ip;
|
|
33
33
|
var PreviouseFilePath;
|
|
34
34
|
if (projectName) {
|
|
35
|
-
loggerPath = loggerPath
|
|
36
|
-
PreviouseFilePath = loggerPath
|
|
35
|
+
loggerPath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
|
|
36
|
+
PreviouseFilePath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
|
|
37
37
|
}
|
|
38
38
|
else if (projectId) {
|
|
39
|
-
loggerPath = loggerPath
|
|
40
|
-
PreviouseFilePath = loggerPath
|
|
39
|
+
loggerPath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
|
|
40
|
+
PreviouseFilePath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
loggerPath = loggerPath
|
|
44
|
-
PreviouseFilePath = loggerPath
|
|
43
|
+
loggerPath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
|
|
44
|
+
PreviouseFilePath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
|
|
45
45
|
}
|
|
46
46
|
if (fs_1.default.existsSync(PreviouseFilePath)) {
|
|
47
47
|
fs_1.default.rmSync(PreviouseFilePath, { recursive: true, force: true });
|
|
@@ -28,16 +28,16 @@ var interceptLoggerNew = function (req, res, next) {
|
|
|
28
28
|
}
|
|
29
29
|
var PreviouseFilePath;
|
|
30
30
|
if (projectName) {
|
|
31
|
-
loggerPath = loggerPath
|
|
32
|
-
PreviouseFilePath = loggerPath
|
|
31
|
+
loggerPath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
|
|
32
|
+
PreviouseFilePath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
|
|
33
33
|
}
|
|
34
34
|
else if (projectId) {
|
|
35
|
-
loggerPath = loggerPath
|
|
36
|
-
PreviouseFilePath = loggerPath
|
|
35
|
+
loggerPath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
|
|
36
|
+
PreviouseFilePath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
loggerPath = loggerPath
|
|
40
|
-
PreviouseFilePath = loggerPath
|
|
39
|
+
loggerPath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
|
|
40
|
+
PreviouseFilePath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
|
|
41
41
|
}
|
|
42
42
|
if (fs_1.default.existsSync(PreviouseFilePath)) {
|
|
43
43
|
fs_1.default.rmSync(PreviouseFilePath, { recursive: true, force: true });
|
|
@@ -47,7 +47,7 @@ var interceptLoggerNew = function (req, res, next) {
|
|
|
47
47
|
res.send = function (data) {
|
|
48
48
|
logger.info(data);
|
|
49
49
|
oldSend.apply(res, arguments);
|
|
50
|
-
request_log_1.saveRequest(req, data);
|
|
50
|
+
(0, request_log_1.saveRequest)(req, data);
|
|
51
51
|
};
|
|
52
52
|
next();
|
|
53
53
|
};
|
|
@@ -22,20 +22,20 @@ var interceptLogger = function (req, res, next) {
|
|
|
22
22
|
reqObject["dbName"] = db.name;
|
|
23
23
|
}
|
|
24
24
|
if (projectName) {
|
|
25
|
-
loggerPath = loggerPath
|
|
25
|
+
loggerPath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerDateFormat)());
|
|
26
26
|
}
|
|
27
27
|
else if (projectId) {
|
|
28
|
-
loggerPath = loggerPath
|
|
28
|
+
loggerPath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerDateFormat)());
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
loggerPath = loggerPath
|
|
31
|
+
loggerPath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerDateFormat)());
|
|
32
32
|
}
|
|
33
33
|
var logger = new drapcode_logger_1.FileLogger(loggerPath).createLogger();
|
|
34
34
|
var oldSend = res.send;
|
|
35
35
|
res.send = function (data) {
|
|
36
36
|
logger.info(data);
|
|
37
37
|
oldSend.apply(res, arguments);
|
|
38
|
-
request_log_1.saveRequest(req, data);
|
|
38
|
+
(0, request_log_1.saveRequest)(req, data);
|
|
39
39
|
};
|
|
40
40
|
next();
|
|
41
41
|
};
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -47,7 +47,7 @@ var saveRequest = function (req, res) {
|
|
|
47
47
|
return __generator(this, function (_a) {
|
|
48
48
|
switch (_a.label) {
|
|
49
49
|
case 0:
|
|
50
|
-
req.body = util_1.isEmpty(req.body) ? req.query : req.body;
|
|
50
|
+
req.body = (0, util_1.isEmpty)(req.body) ? req.query : req.body;
|
|
51
51
|
ip = req.headers["x-forwarded-for"] ||
|
|
52
52
|
req.connection.remoteAddress ||
|
|
53
53
|
req.socket.remoteAddress ||
|
|
@@ -62,13 +62,13 @@ var saveRequest = function (req, res) {
|
|
|
62
62
|
response: JSON.stringify(res),
|
|
63
63
|
ipAddress: ip,
|
|
64
64
|
};
|
|
65
|
-
return [4 /*yield*/, drapcode_redis_1.redis_get_method("requestLog")];
|
|
65
|
+
return [4 /*yield*/, (0, drapcode_redis_1.redis_get_method)("requestLog")];
|
|
66
66
|
case 1:
|
|
67
67
|
redisData = _a.sent();
|
|
68
68
|
if (!redisData)
|
|
69
69
|
redisData = [];
|
|
70
70
|
redisData.push(respObj);
|
|
71
|
-
return [4 /*yield*/, drapcode_redis_1.redis_set_method("requestLog", redisData)];
|
|
71
|
+
return [4 /*yield*/, (0, drapcode_redis_1.redis_set_method)("requestLog", redisData)];
|
|
72
72
|
case 2:
|
|
73
73
|
_a.sent();
|
|
74
74
|
return [2 /*return*/];
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -35,12 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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));
|
|
44
46
|
};
|
|
45
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -116,7 +118,7 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
116
118
|
var apiErrorMessage;
|
|
117
119
|
var apiErrorValue;
|
|
118
120
|
if (result && result !== "undefined" && result !== "null") {
|
|
119
|
-
console.log("handleMultErrorConfig result :>> "
|
|
121
|
+
console.log("handleMultErrorConfig result :>> ".concat(Object.keys(result)));
|
|
120
122
|
apiErrorMessage = lodash_1.default.get(result, message);
|
|
121
123
|
if (apiErrorMessage) {
|
|
122
124
|
console.log("*** utility 3 ***");
|
|
@@ -146,7 +148,7 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
146
148
|
apiErrorValue = status;
|
|
147
149
|
}
|
|
148
150
|
console.log("apiErrorValue", apiErrorValue);
|
|
149
|
-
apiErrorValue = ""
|
|
151
|
+
apiErrorValue = "".concat(apiErrorValue);
|
|
150
152
|
console.log("apiErrorMessage", apiErrorMessage);
|
|
151
153
|
console.log("apiErrorValue", apiErrorValue);
|
|
152
154
|
if (value && apiErrorValue == value) {
|
|
@@ -183,7 +185,7 @@ var nestedValue = function (data, messages) {
|
|
|
183
185
|
messages.push(value);
|
|
184
186
|
}
|
|
185
187
|
else if (Array.isArray(value)) {
|
|
186
|
-
messages =
|
|
188
|
+
messages = __spreadArray(__spreadArray([], messages, true), value, true);
|
|
187
189
|
}
|
|
188
190
|
else {
|
|
189
191
|
if (Object.keys(value).length) {
|
package/build/utils/date-util.js
CHANGED
|
@@ -29,11 +29,11 @@ exports.createLogsDateFormat = createLogsDateFormat;
|
|
|
29
29
|
var getDateValue = function (value, timezone) {
|
|
30
30
|
if (timezone === void 0) { timezone = ""; }
|
|
31
31
|
if (!value)
|
|
32
|
-
return exports.createLogsDateFormat(timezone);
|
|
32
|
+
return (0, exports.createLogsDateFormat)(timezone);
|
|
33
33
|
var dateFormat = "YYYY-MM-DDTHH:mm:ss.SSS";
|
|
34
34
|
var _a = value.split(":"), type = _a[0], number = _a[1], unit = _a[2];
|
|
35
35
|
if (!["ADD", "SUB"].includes(type))
|
|
36
|
-
return exports.createLogsDateFormat(timezone);
|
|
36
|
+
return (0, exports.createLogsDateFormat)(timezone);
|
|
37
37
|
var dateUnit = getDateUnit(unit);
|
|
38
38
|
var result;
|
|
39
39
|
if (type === "ADD") {
|
|
@@ -80,7 +80,7 @@ var timezoneDateParse = function (value, nextDay, prevDay) {
|
|
|
80
80
|
if (prevDay && value.length <= 10) {
|
|
81
81
|
timeZoneDate = timeZoneDate.subtract(1, "days");
|
|
82
82
|
}
|
|
83
|
-
console.log("If it was for end date "
|
|
83
|
+
console.log("If it was for end date ".concat(nextDay, " then"), timeZoneDate);
|
|
84
84
|
timeZoneDate = timeZoneDate.format("YYYY-MM-DDTHH:mm:ss");
|
|
85
85
|
console.log("Format Date into date string", timeZoneDate);
|
|
86
86
|
return new Date(timeZoneDate);
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -35,12 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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));
|
|
44
46
|
};
|
|
45
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -87,7 +89,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
87
89
|
searchQueryObj = null;
|
|
88
90
|
if (searchObj) {
|
|
89
91
|
_a = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
|
|
90
|
-
aggregateQuery =
|
|
92
|
+
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery, true), searchAggregateQuery, true);
|
|
91
93
|
console.log("likeQuery after getSearchObjQuery", JSON.stringify(likeQuery));
|
|
92
94
|
if (likeQuery && likeQuery.length > 0) {
|
|
93
95
|
searchQueryObj = likeQuery;
|
|
@@ -105,7 +107,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
105
107
|
else if (searchObj) {
|
|
106
108
|
console.log("I donot have filter query");
|
|
107
109
|
_b = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
|
|
108
|
-
aggregateQuery =
|
|
110
|
+
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery, true), searchAggregateQuery, true);
|
|
109
111
|
if (likeQuery.length) {
|
|
110
112
|
// aggregateQuery.push({ $match: { $or: likeQuery } });
|
|
111
113
|
aggregateQuery.push({ $match: { $and: likeQuery } });
|
|
@@ -126,7 +128,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
126
128
|
if (field.type === "belongsTo") {
|
|
127
129
|
aggregateQuery.push({
|
|
128
130
|
$lookup: {
|
|
129
|
-
from: ""
|
|
131
|
+
from: "".concat(collectionName_1),
|
|
130
132
|
localField: field.fieldName,
|
|
131
133
|
foreignField: "uuid",
|
|
132
134
|
as: field.fieldName,
|
|
@@ -141,8 +143,8 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
141
143
|
else {
|
|
142
144
|
aggregateQuery.push({
|
|
143
145
|
$lookup: {
|
|
144
|
-
from: ""
|
|
145
|
-
let: (_b = {}, _b[""
|
|
146
|
+
from: "".concat(collectionName_1),
|
|
147
|
+
let: (_b = {}, _b["".concat(field.fieldName)] = "$".concat(field.fieldName), _b),
|
|
146
148
|
pipeline: [
|
|
147
149
|
{
|
|
148
150
|
$match: {
|
|
@@ -152,10 +154,10 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
152
154
|
{
|
|
153
155
|
$cond: {
|
|
154
156
|
if: {
|
|
155
|
-
$in: ["$$"
|
|
157
|
+
$in: ["$$".concat(field.fieldName), ["", null]],
|
|
156
158
|
},
|
|
157
159
|
then: [],
|
|
158
|
-
else: { $ifNull: ["$$"
|
|
160
|
+
else: { $ifNull: ["$$".concat(field.fieldName), []] },
|
|
159
161
|
},
|
|
160
162
|
},
|
|
161
163
|
],
|
|
@@ -188,10 +190,10 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
188
190
|
aggregateQuery.push({
|
|
189
191
|
$lookup: {
|
|
190
192
|
from: "user",
|
|
191
|
-
let: (_c = {}, _c[""
|
|
193
|
+
let: (_c = {}, _c["".concat(field.fieldName)] = "$".concat(field.fieldName), _c),
|
|
192
194
|
pipeline: [
|
|
193
195
|
{
|
|
194
|
-
$match: { $expr: { $eq: ["$uuid", "$$"
|
|
196
|
+
$match: { $expr: { $eq: ["$uuid", "$$".concat(field.fieldName)] } },
|
|
195
197
|
},
|
|
196
198
|
{ $project: { _id: 0, password: 0 } },
|
|
197
199
|
],
|
|
@@ -203,7 +205,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
203
205
|
_e.sent();
|
|
204
206
|
_e.label = 2;
|
|
205
207
|
case 2:
|
|
206
|
-
if (finder != "COUNT" && !util_1.isEmpty(projection)) {
|
|
208
|
+
if (finder != "COUNT" && !(0, util_1.isEmpty)(projection)) {
|
|
207
209
|
aggregateQuery.push({ $project: projection });
|
|
208
210
|
}
|
|
209
211
|
if (finder === "COUNT") {
|
|
@@ -224,8 +226,8 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
224
226
|
}
|
|
225
227
|
console.log("==> aggregateQuery", aggregateQuery);
|
|
226
228
|
console.log("==> aggregateQuery", JSON.stringify(aggregateQuery));
|
|
227
|
-
queryStr = ".aggregate("
|
|
228
|
-
str = "req.db.collection('"
|
|
229
|
+
queryStr = ".aggregate(".concat(JSON.stringify(aggregateQuery), ", { collation: { locale: \"en\" } })");
|
|
230
|
+
str = "req.db.collection('".concat(collectionName, "')").concat(queryStr);
|
|
229
231
|
str += ".toArray()";
|
|
230
232
|
return [2 /*return*/, str];
|
|
231
233
|
}
|
|
@@ -265,7 +267,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
|
|
|
265
267
|
filterQuery[lastKey].push(mongoQuery);
|
|
266
268
|
}
|
|
267
269
|
else {
|
|
268
|
-
filterQuery["$or"
|
|
270
|
+
filterQuery["$or".concat(index)] = [mongoQuery];
|
|
269
271
|
}
|
|
270
272
|
}
|
|
271
273
|
else if (queryObj.conjunctionType == "AND") {
|
|
@@ -274,11 +276,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
|
|
|
274
276
|
filterQuery[lastKey].push(mongoQuery);
|
|
275
277
|
}
|
|
276
278
|
else {
|
|
277
|
-
filterQuery["$and"
|
|
279
|
+
filterQuery["$and".concat(index)] = [mongoQuery];
|
|
278
280
|
}
|
|
279
281
|
}
|
|
280
282
|
else {
|
|
281
|
-
filterQuery["$or"
|
|
283
|
+
filterQuery["$or".concat(index)] = [mongoQuery];
|
|
282
284
|
}
|
|
283
285
|
});
|
|
284
286
|
console.log("==> *** filterQuery mongoFilterQuery :>> ", filterQuery);
|
|
@@ -297,13 +299,13 @@ var mongoSelectQuery = function (query) {
|
|
|
297
299
|
if (fieldsInclude[0] === "*") {
|
|
298
300
|
fieldsExclude.map(function (field) {
|
|
299
301
|
if (field)
|
|
300
|
-
return (projection[""
|
|
302
|
+
return (projection["".concat(field)] = 0);
|
|
301
303
|
});
|
|
302
304
|
}
|
|
303
305
|
else {
|
|
304
306
|
fieldsInclude.map(function (field) {
|
|
305
307
|
if (field)
|
|
306
|
-
return (projection[""
|
|
308
|
+
return (projection["".concat(field)] = 1);
|
|
307
309
|
});
|
|
308
310
|
}
|
|
309
311
|
return projection;
|
|
@@ -335,7 +337,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
335
337
|
//TODO: In case of this, we assign some random string to avoid resulting all values
|
|
336
338
|
//TODO: This is use case in Spot Factor Project, where a new user with blank value able to see all records
|
|
337
339
|
//TODO: Discussed on meet
|
|
338
|
-
fieldValue = "random_string_since_field_not_present_"
|
|
340
|
+
fieldValue = "random_string_since_field_not_present_".concat((0, moment_1.default)(1318874398806).valueOf());
|
|
339
341
|
}
|
|
340
342
|
console.log("fieldValue queryToMongo 1", fieldValue);
|
|
341
343
|
var isDate = checkDate(fieldValue);
|
|
@@ -403,7 +405,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
403
405
|
return _q = {},
|
|
404
406
|
_q[field] = {
|
|
405
407
|
$gte: fieldValue,
|
|
406
|
-
$lt: date_util_1.nextDayDate(fieldValue),
|
|
408
|
+
$lt: (0, date_util_1.nextDayDate)(fieldValue),
|
|
407
409
|
},
|
|
408
410
|
_q;
|
|
409
411
|
// Todo: Remove this if works properly
|
|
@@ -459,7 +461,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
459
461
|
},
|
|
460
462
|
_y;
|
|
461
463
|
if (key == drapcode_constant_1.BETWEEN) {
|
|
462
|
-
var _0 = exports.getMinMaxValue(fieldValue), startValue = _0.startValue, endValue = _0.endValue, isInteger = _0.isInteger;
|
|
464
|
+
var _0 = (0, exports.getMinMaxValue)(fieldValue), startValue = _0.startValue, endValue = _0.endValue, isInteger = _0.isInteger;
|
|
463
465
|
return _z = {},
|
|
464
466
|
_z[field] = {
|
|
465
467
|
$gte: isInteger ? +startValue : startValue,
|
|
@@ -509,13 +511,13 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
509
511
|
return valueList_1;
|
|
510
512
|
}
|
|
511
513
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
512
|
-
var _a = exports.getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
514
|
+
var _a = (0, exports.getMinMaxValue)(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
513
515
|
if (requiredExternal) {
|
|
514
|
-
startValue_1 = ""
|
|
515
|
-
endValue_1 = ""
|
|
516
|
+
startValue_1 = "".concat(externalParams[startValue_1]);
|
|
517
|
+
endValue_1 = "".concat(externalParams[endValue_1]);
|
|
516
518
|
}
|
|
517
519
|
else {
|
|
518
|
-
if (
|
|
520
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) {
|
|
519
521
|
return startValue_1.includes(cnst);
|
|
520
522
|
})) {
|
|
521
523
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser, timezone);
|
|
@@ -523,7 +525,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
523
525
|
else {
|
|
524
526
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
525
527
|
}
|
|
526
|
-
if (
|
|
528
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
527
529
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser, timezone);
|
|
528
530
|
}
|
|
529
531
|
else {
|
|
@@ -539,10 +541,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
539
541
|
}
|
|
540
542
|
//TODO: Need to figure out the params should be treated as number/string
|
|
541
543
|
if (!isNaN(startValue_1)) {
|
|
542
|
-
return startValue_1
|
|
544
|
+
return "".concat(startValue_1, "---").concat(endValue_1, "^");
|
|
543
545
|
}
|
|
544
546
|
else
|
|
545
|
-
return startValue_1
|
|
547
|
+
return "".concat(startValue_1, "---").concat(endValue_1);
|
|
546
548
|
}
|
|
547
549
|
console.log("==> value", value);
|
|
548
550
|
console.log("==> currentUser", currentUser);
|
|
@@ -638,18 +640,18 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
638
640
|
if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
639
641
|
return getValueOfProjectConstant(value, {}, timezone);
|
|
640
642
|
}
|
|
641
|
-
if (exports.isEntityInCondition(value)) {
|
|
643
|
+
if ((0, exports.isEntityInCondition)(value)) {
|
|
642
644
|
var key_1 = value.replace("ENTITY::", "");
|
|
643
645
|
return externalParams[key_1] ? externalParams[key_1] : "";
|
|
644
646
|
}
|
|
645
647
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
646
648
|
if (requiredExternal) {
|
|
647
649
|
//TODO: Value returns from here undefined.
|
|
648
|
-
var externalParamValue = externalParams[""
|
|
650
|
+
var externalParamValue = externalParams["".concat(value)];
|
|
649
651
|
if (!isNaN(externalParamValue)) {
|
|
650
652
|
return +externalParamValue;
|
|
651
653
|
}
|
|
652
|
-
return externalParams[""
|
|
654
|
+
return externalParams["".concat(value)];
|
|
653
655
|
}
|
|
654
656
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
655
657
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -680,11 +682,11 @@ var getValueOfProjectConstant = function (value, currentUser, timezone) {
|
|
|
680
682
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
681
683
|
return currentUser["uuid"];
|
|
682
684
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
683
|
-
result = date_util_1.createLoggerDateFormat(timezone);
|
|
685
|
+
result = (0, date_util_1.createLoggerDateFormat)(timezone);
|
|
684
686
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
685
|
-
result = date_util_1.createLogsDateFormat(timezone);
|
|
687
|
+
result = (0, date_util_1.createLogsDateFormat)(timezone);
|
|
686
688
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
687
|
-
result = date_util_1.getDateValue(value, timezone);
|
|
689
|
+
result = (0, date_util_1.getDateValue)(value, timezone);
|
|
688
690
|
return result;
|
|
689
691
|
};
|
|
690
692
|
var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
@@ -700,11 +702,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
700
702
|
// if input is string and db field type is boolean
|
|
701
703
|
searchAggregateQuery.push({
|
|
702
704
|
$addFields: (_b = {},
|
|
703
|
-
_b["_"
|
|
705
|
+
_b["_".concat(key)] = "$".concat(key),
|
|
704
706
|
_b),
|
|
705
707
|
});
|
|
706
708
|
likeQuery.push((_c = {},
|
|
707
|
-
_c["_"
|
|
709
|
+
_c["_".concat(key)] = toBoolean(value),
|
|
708
710
|
_c));
|
|
709
711
|
}
|
|
710
712
|
else if ([
|
|
@@ -716,22 +718,22 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
716
718
|
// if input is string and db field type is array
|
|
717
719
|
searchAggregateQuery.push({
|
|
718
720
|
$addFields: (_d = {},
|
|
719
|
-
_d["_"
|
|
721
|
+
_d["_".concat(key)] = "$".concat(key),
|
|
720
722
|
_d),
|
|
721
723
|
});
|
|
722
724
|
likeQuery.push((_e = {},
|
|
723
|
-
_e["_"
|
|
725
|
+
_e["_".concat(key)] = { $all: [value] },
|
|
724
726
|
_e));
|
|
725
727
|
}
|
|
726
728
|
else if (searchQueryTypeKey === "tel") {
|
|
727
729
|
// handling value when db field type is tel
|
|
728
730
|
searchAggregateQuery.push({
|
|
729
731
|
$addFields: (_f = {},
|
|
730
|
-
_f["_"
|
|
732
|
+
_f["_".concat(key)] = { $toString: "$".concat(key) },
|
|
731
733
|
_f),
|
|
732
734
|
});
|
|
733
735
|
likeQuery.push((_g = {},
|
|
734
|
-
_g["_"
|
|
736
|
+
_g["_".concat(key)] = {
|
|
735
737
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
736
738
|
$options: "i",
|
|
737
739
|
},
|
|
@@ -741,11 +743,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
741
743
|
// handling value when db field type is Double/Int
|
|
742
744
|
searchAggregateQuery.push({
|
|
743
745
|
$addFields: (_h = {},
|
|
744
|
-
_h["_"
|
|
746
|
+
_h["_".concat(key)] = { $toString: { $toLong: "$".concat(key) } },
|
|
745
747
|
_h),
|
|
746
748
|
});
|
|
747
749
|
likeQuery.push((_j = {},
|
|
748
|
-
_j["_"
|
|
750
|
+
_j["_".concat(key)] = {
|
|
749
751
|
$regex: value,
|
|
750
752
|
$options: "i",
|
|
751
753
|
},
|
|
@@ -757,20 +759,20 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
757
759
|
fieldKey = fieldKey.replace("end_", "");
|
|
758
760
|
searchAggregateQuery.push({
|
|
759
761
|
$addFields: (_k = {},
|
|
760
|
-
_k["_"
|
|
762
|
+
_k["_".concat(key)] = { $toString: "$".concat(fieldKey) },
|
|
761
763
|
_k),
|
|
762
764
|
});
|
|
763
765
|
if (key.startsWith("start_")) {
|
|
764
766
|
likeQuery.push((_l = {},
|
|
765
|
-
_l["_"
|
|
766
|
-
$gte: date_util_1.timezoneDateParse(value, false, true),
|
|
767
|
+
_l["_".concat(key)] = {
|
|
768
|
+
$gte: (0, date_util_1.timezoneDateParse)(value, false, true),
|
|
767
769
|
},
|
|
768
770
|
_l));
|
|
769
771
|
}
|
|
770
772
|
else if (key.startsWith("end_")) {
|
|
771
773
|
likeQuery.push((_m = {},
|
|
772
|
-
_m["_"
|
|
773
|
-
$lt: date_util_1.timezoneDateParse(value, true),
|
|
774
|
+
_m["_".concat(key)] = {
|
|
775
|
+
$lt: (0, date_util_1.timezoneDateParse)(value, true),
|
|
774
776
|
},
|
|
775
777
|
_m));
|
|
776
778
|
}
|
|
@@ -781,11 +783,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
781
783
|
// converting db field to string first
|
|
782
784
|
searchAggregateQuery.push({
|
|
783
785
|
$addFields: (_o = {},
|
|
784
|
-
_o["_"
|
|
786
|
+
_o["_".concat(key)] = { $toString: "$".concat(key) },
|
|
785
787
|
_o),
|
|
786
788
|
});
|
|
787
789
|
likeQuery.push((_p = {},
|
|
788
|
-
_p["_"
|
|
790
|
+
_p["_".concat(key)] = {
|
|
789
791
|
$regex: value,
|
|
790
792
|
$options: "i",
|
|
791
793
|
},
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
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
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -35,12 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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));
|
|
44
46
|
};
|
|
45
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
48
|
exports.queryParserNew = void 0;
|
|
@@ -83,11 +85,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
83
85
|
if (searchQueryTypeObj[key]) {
|
|
84
86
|
aggregateQuery.push({
|
|
85
87
|
$addFields: (_b = {},
|
|
86
|
-
_b["_"
|
|
88
|
+
_b["_".concat(key)] = { $toString: "$".concat(key) },
|
|
87
89
|
_b),
|
|
88
90
|
});
|
|
89
91
|
searchQueryObj_1.push((_c = {},
|
|
90
|
-
_c["_"
|
|
92
|
+
_c["_".concat(key)] = {
|
|
91
93
|
$regex: value,
|
|
92
94
|
$options: "i",
|
|
93
95
|
},
|
|
@@ -121,11 +123,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
121
123
|
// if input is string and db field type is boolean
|
|
122
124
|
aggregateQuery.push({
|
|
123
125
|
$addFields: (_b = {},
|
|
124
|
-
_b["_"
|
|
126
|
+
_b["_".concat(key)] = "$".concat(key),
|
|
125
127
|
_b),
|
|
126
128
|
});
|
|
127
129
|
likeQuery_1.push((_c = {},
|
|
128
|
-
_c["_"
|
|
130
|
+
_c["_".concat(key)] = toBoolean(value),
|
|
129
131
|
_c));
|
|
130
132
|
}
|
|
131
133
|
else if ([
|
|
@@ -137,22 +139,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
137
139
|
// if input is string and db field type is array
|
|
138
140
|
aggregateQuery.push({
|
|
139
141
|
$addFields: (_d = {},
|
|
140
|
-
_d["_"
|
|
142
|
+
_d["_".concat(key)] = "$".concat(key),
|
|
141
143
|
_d),
|
|
142
144
|
});
|
|
143
145
|
likeQuery_1.push((_e = {},
|
|
144
|
-
_e["_"
|
|
146
|
+
_e["_".concat(key)] = { $all: [value] },
|
|
145
147
|
_e));
|
|
146
148
|
}
|
|
147
149
|
else if (searchQueryTypeObj[key] === "tel") {
|
|
148
150
|
// handling value when db field type is tel
|
|
149
151
|
aggregateQuery.push({
|
|
150
152
|
$addFields: (_f = {},
|
|
151
|
-
_f["_"
|
|
153
|
+
_f["_".concat(key)] = { $toString: "$".concat(key) },
|
|
152
154
|
_f),
|
|
153
155
|
});
|
|
154
156
|
likeQuery_1.push((_g = {},
|
|
155
|
-
_g["_"
|
|
157
|
+
_g["_".concat(key)] = {
|
|
156
158
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
157
159
|
$options: "i",
|
|
158
160
|
},
|
|
@@ -162,11 +164,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
162
164
|
// handling value when db field type is Double/Int
|
|
163
165
|
aggregateQuery.push({
|
|
164
166
|
$addFields: (_h = {},
|
|
165
|
-
_h["_"
|
|
167
|
+
_h["_".concat(key)] = { $toString: { $toLong: "$".concat(key) } },
|
|
166
168
|
_h),
|
|
167
169
|
});
|
|
168
170
|
likeQuery_1.push((_j = {},
|
|
169
|
-
_j["_"
|
|
171
|
+
_j["_".concat(key)] = {
|
|
170
172
|
$regex: value,
|
|
171
173
|
$options: "i",
|
|
172
174
|
},
|
|
@@ -177,11 +179,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
177
179
|
// converting db field to string first
|
|
178
180
|
aggregateQuery.push({
|
|
179
181
|
$addFields: (_k = {},
|
|
180
|
-
_k["_"
|
|
182
|
+
_k["_".concat(key)] = { $toString: "$".concat(key) },
|
|
181
183
|
_k),
|
|
182
184
|
});
|
|
183
185
|
likeQuery_1.push((_l = {},
|
|
184
|
-
_l["_"
|
|
186
|
+
_l["_".concat(key)] = {
|
|
185
187
|
$regex: value,
|
|
186
188
|
$options: "i",
|
|
187
189
|
},
|
|
@@ -216,7 +218,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
216
218
|
if (field.type === "belongsTo") {
|
|
217
219
|
aggregateQuery.push({
|
|
218
220
|
$lookup: {
|
|
219
|
-
from: ""
|
|
221
|
+
from: "".concat(collectionName_1),
|
|
220
222
|
localField: field.fieldName,
|
|
221
223
|
foreignField: "uuid",
|
|
222
224
|
as: field.fieldName,
|
|
@@ -231,8 +233,8 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
231
233
|
else {
|
|
232
234
|
aggregateQuery.push({
|
|
233
235
|
$lookup: {
|
|
234
|
-
from: ""
|
|
235
|
-
let: (_b = {}, _b[""
|
|
236
|
+
from: "".concat(collectionName_1),
|
|
237
|
+
let: (_b = {}, _b["".concat(field.fieldName)] = "$".concat(field.fieldName), _b),
|
|
236
238
|
pipeline: [
|
|
237
239
|
{
|
|
238
240
|
$match: {
|
|
@@ -242,10 +244,10 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
242
244
|
{
|
|
243
245
|
$cond: {
|
|
244
246
|
if: {
|
|
245
|
-
$in: ["$$"
|
|
247
|
+
$in: ["$$".concat(field.fieldName), ["", null]],
|
|
246
248
|
},
|
|
247
249
|
then: [],
|
|
248
|
-
else: { $ifNull: ["$$"
|
|
250
|
+
else: { $ifNull: ["$$".concat(field.fieldName), []] },
|
|
249
251
|
},
|
|
250
252
|
},
|
|
251
253
|
],
|
|
@@ -278,10 +280,10 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
278
280
|
aggregateQuery.push({
|
|
279
281
|
$lookup: {
|
|
280
282
|
from: "user",
|
|
281
|
-
let: (_c = {}, _c[""
|
|
283
|
+
let: (_c = {}, _c["".concat(field.fieldName)] = "$".concat(field.fieldName), _c),
|
|
282
284
|
pipeline: [
|
|
283
285
|
{
|
|
284
|
-
$match: { $expr: { $eq: ["$uuid", "$$"
|
|
286
|
+
$match: { $expr: { $eq: ["$uuid", "$$".concat(field.fieldName)] } },
|
|
285
287
|
},
|
|
286
288
|
{ $project: { _id: 0, password: 0 } },
|
|
287
289
|
],
|
|
@@ -294,7 +296,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
294
296
|
_b.label = 2;
|
|
295
297
|
case 2:
|
|
296
298
|
if (!["COUNT", "SUM", "AVG", "MIN", "MAX"].includes(finder) &&
|
|
297
|
-
!util_1.isEmpty(projection)) {
|
|
299
|
+
!(0, util_1.isEmpty)(projection)) {
|
|
298
300
|
aggregateQuery.push({ $project: projection });
|
|
299
301
|
}
|
|
300
302
|
if (finder === "COUNT") {
|
|
@@ -302,22 +304,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
302
304
|
}
|
|
303
305
|
else if (finder === "SUM") {
|
|
304
306
|
aggregateQuery.push({
|
|
305
|
-
$group: { _id: null, total: { $sum: "$"
|
|
307
|
+
$group: { _id: null, total: { $sum: "$".concat(aggregateFunctionField) } },
|
|
306
308
|
});
|
|
307
309
|
}
|
|
308
310
|
else if (finder === "AVG") {
|
|
309
311
|
aggregateQuery.push({
|
|
310
|
-
$group: { _id: null, average: { $avg: "$"
|
|
312
|
+
$group: { _id: null, average: { $avg: "$".concat(aggregateFunctionField) } },
|
|
311
313
|
});
|
|
312
314
|
}
|
|
313
315
|
else if (finder === "MIN") {
|
|
314
316
|
aggregateQuery.push({
|
|
315
|
-
$group: { _id: null, minimum: { $min: "$"
|
|
317
|
+
$group: { _id: null, minimum: { $min: "$".concat(aggregateFunctionField) } },
|
|
316
318
|
});
|
|
317
319
|
}
|
|
318
320
|
else if (finder === "MAX") {
|
|
319
321
|
aggregateQuery.push({
|
|
320
|
-
$group: { _id: null, maximum: { $max: "$"
|
|
322
|
+
$group: { _id: null, maximum: { $max: "$".concat(aggregateFunctionField) } },
|
|
321
323
|
});
|
|
322
324
|
}
|
|
323
325
|
offset = externalParams.offset || 0;
|
|
@@ -333,8 +335,8 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
333
335
|
if (finder != "COUNT" && limit) {
|
|
334
336
|
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
335
337
|
}
|
|
336
|
-
queryStr = ".aggregate("
|
|
337
|
-
str = "req.db.collection('"
|
|
338
|
+
queryStr = ".aggregate(".concat(JSON.stringify(aggregateQuery), ", { collation: { locale: \"en\" } })");
|
|
339
|
+
str = "req.db.collection('".concat(collectionName, "')").concat(queryStr);
|
|
338
340
|
str += ".toArray()";
|
|
339
341
|
return [2 /*return*/, str];
|
|
340
342
|
}
|
|
@@ -371,7 +373,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
371
373
|
filterQuery[lastKey].push(mongoQuery);
|
|
372
374
|
}
|
|
373
375
|
else {
|
|
374
|
-
filterQuery["$or"
|
|
376
|
+
filterQuery["$or".concat(index)] = [mongoQuery];
|
|
375
377
|
}
|
|
376
378
|
}
|
|
377
379
|
else if (queryObj.conjunctionType == "AND") {
|
|
@@ -380,11 +382,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
380
382
|
filterQuery[lastKey].push(mongoQuery);
|
|
381
383
|
}
|
|
382
384
|
else {
|
|
383
|
-
filterQuery["$and"
|
|
385
|
+
filterQuery["$and".concat(index)] = [mongoQuery];
|
|
384
386
|
}
|
|
385
387
|
}
|
|
386
388
|
else {
|
|
387
|
-
filterQuery["$or"
|
|
389
|
+
filterQuery["$or".concat(index)] = [mongoQuery];
|
|
388
390
|
}
|
|
389
391
|
});
|
|
390
392
|
console.log("==> *** filterQuery #2 :>> ", filterQuery);
|
|
@@ -400,13 +402,13 @@ var mongoSelectQuery = function (query) {
|
|
|
400
402
|
if (fieldsInclude[0] === "*") {
|
|
401
403
|
fieldsExclude.map(function (field) {
|
|
402
404
|
if (field)
|
|
403
|
-
return (projection[""
|
|
405
|
+
return (projection["".concat(field)] = 0);
|
|
404
406
|
});
|
|
405
407
|
}
|
|
406
408
|
else {
|
|
407
409
|
fieldsInclude.map(function (field) {
|
|
408
410
|
if (field)
|
|
409
|
-
return (projection[""
|
|
411
|
+
return (projection["".concat(field)] = 1);
|
|
410
412
|
});
|
|
411
413
|
}
|
|
412
414
|
return projection;
|
|
@@ -497,7 +499,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
497
499
|
return _r = {},
|
|
498
500
|
_r[field] = {
|
|
499
501
|
$gte: fieldValue,
|
|
500
|
-
$lt: new Date(date_util_1.nextDayDate(fieldValue)),
|
|
502
|
+
$lt: new Date((0, date_util_1.nextDayDate)(fieldValue)),
|
|
501
503
|
},
|
|
502
504
|
_r;
|
|
503
505
|
}
|
|
@@ -575,11 +577,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
575
577
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
576
578
|
var _a = getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
577
579
|
if (requiredExternal) {
|
|
578
|
-
startValue_1 = ""
|
|
579
|
-
endValue_1 = ""
|
|
580
|
+
startValue_1 = "".concat(externalParams[startValue_1]);
|
|
581
|
+
endValue_1 = "".concat(externalParams[endValue_1]);
|
|
580
582
|
}
|
|
581
583
|
else {
|
|
582
|
-
if (
|
|
584
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) {
|
|
583
585
|
return startValue_1.includes(cnst);
|
|
584
586
|
})) {
|
|
585
587
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
|
|
@@ -587,7 +589,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
587
589
|
else {
|
|
588
590
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
589
591
|
}
|
|
590
|
-
if (
|
|
592
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
591
593
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
|
|
592
594
|
}
|
|
593
595
|
else {
|
|
@@ -604,10 +606,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
604
606
|
//TODO: Need to figure out the params should be treated as number/string
|
|
605
607
|
if (!isNaN(startValue_1)) {
|
|
606
608
|
console.log("I am Number");
|
|
607
|
-
return startValue_1
|
|
609
|
+
return "".concat(startValue_1, "---").concat(endValue_1, "^");
|
|
608
610
|
}
|
|
609
611
|
else
|
|
610
|
-
return startValue_1
|
|
612
|
+
return "".concat(startValue_1, "---").concat(endValue_1);
|
|
611
613
|
}
|
|
612
614
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
613
615
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -645,11 +647,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
645
647
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
646
648
|
if (requiredExternal) {
|
|
647
649
|
//TODO: Value returns from here undefined.
|
|
648
|
-
var externalParamValue = externalParams[""
|
|
650
|
+
var externalParamValue = externalParams["".concat(value)];
|
|
649
651
|
if (!isNaN(externalParamValue)) {
|
|
650
652
|
return +externalParamValue;
|
|
651
653
|
}
|
|
652
|
-
return externalParams[""
|
|
654
|
+
return externalParams["".concat(value)];
|
|
653
655
|
}
|
|
654
656
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
655
657
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -676,9 +678,9 @@ var getValueOfProjectConstant = function (value, currentUser) {
|
|
|
676
678
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
677
679
|
return currentUser["uuid"];
|
|
678
680
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
679
|
-
return date_util_1.createLoggerDateFormat();
|
|
681
|
+
return (0, date_util_1.createLoggerDateFormat)();
|
|
680
682
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
681
|
-
return date_util_1.createLogsDateFormat();
|
|
683
|
+
return (0, date_util_1.createLogsDateFormat)();
|
|
682
684
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
683
|
-
return date_util_1.getDateValue(value);
|
|
685
|
+
return (0, date_util_1.getDateValue)(value);
|
|
684
686
|
};
|
package/build/utils/util.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const validateString: (str: string) => false | "String should not contain special characters" | "String should not contain any number";
|
|
2
2
|
export declare const camelize: (str: string) => string;
|
|
3
|
-
export declare const clearSpaceAndReformat: (text: string, separator?: string
|
|
3
|
+
export declare const clearSpaceAndReformat: (text: string, separator?: string) => string;
|
|
4
4
|
export declare const isEmpty: (obj: any) => boolean;
|
|
5
5
|
export declare const isEmptyObject: (object: any) => boolean;
|
|
6
6
|
export declare const isObject: (item: any) => any;
|
package/build/utils/util.js
CHANGED
|
@@ -38,7 +38,7 @@ var validateString = function (str) {
|
|
|
38
38
|
};
|
|
39
39
|
exports.validateString = validateString;
|
|
40
40
|
var camelize = function (str) {
|
|
41
|
-
str = exports.clearSpaceAndReformat(str);
|
|
41
|
+
str = (0, exports.clearSpaceAndReformat)(str);
|
|
42
42
|
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
43
43
|
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
44
44
|
});
|
|
@@ -165,8 +165,8 @@ var cleanCollectionAndFieldName = function (str) {
|
|
|
165
165
|
};
|
|
166
166
|
exports.cleanCollectionAndFieldName = cleanCollectionAndFieldName;
|
|
167
167
|
var formatCollectionAndFieldName = function (str) {
|
|
168
|
-
var updateString = exports.cleanCollectionAndFieldName(str);
|
|
169
|
-
return exports.clearSpaceAndReformat(updateString.trim(), "_");
|
|
168
|
+
var updateString = (0, exports.cleanCollectionAndFieldName)(str);
|
|
169
|
+
return (0, exports.clearSpaceAndReformat)(updateString.trim(), "_");
|
|
170
170
|
};
|
|
171
171
|
exports.formatCollectionAndFieldName = formatCollectionAndFieldName;
|
|
172
172
|
var restructureData = function (data) {
|
|
@@ -197,7 +197,7 @@ var restructureData = function (data) {
|
|
|
197
197
|
exports.restructureData = restructureData;
|
|
198
198
|
var checkAndCompareValue = function (input1, input2) {
|
|
199
199
|
return Array.isArray(input2)
|
|
200
|
-
? exports.arraysEqual(input1, input2.map(function (key) { return key.value; }))
|
|
200
|
+
? (0, exports.arraysEqual)(input1, input2.map(function (key) { return key.value; }))
|
|
201
201
|
: input1 === input2.value;
|
|
202
202
|
};
|
|
203
203
|
exports.checkAndCompareValue = checkAndCompareValue;
|
|
@@ -207,7 +207,7 @@ var arraysEqual = function (array1, array2) {
|
|
|
207
207
|
return false;
|
|
208
208
|
for (var i = 0; i < array1.length; i++ // assert each element equal
|
|
209
209
|
)
|
|
210
|
-
if (!exports.arraysEqual(array1[i], array2[i]))
|
|
210
|
+
if (!(0, exports.arraysEqual)(array1[i], array2[i]))
|
|
211
211
|
return false;
|
|
212
212
|
return true;
|
|
213
213
|
}
|
|
@@ -242,7 +242,7 @@ var formatCustomCSSClasses = function (projectCustomCSSClasses) {
|
|
|
242
242
|
.replace(/"([^"]+)"/g, "$1")
|
|
243
243
|
.split(",")
|
|
244
244
|
.join(";");
|
|
245
|
-
projectCustomCSSClassesData += ""
|
|
245
|
+
projectCustomCSSClassesData += "".concat(element.class.startsWith(".") ? element.class : "." + element.class).concat(element.pseudoClass ? ":" + element.pseudoClass : "").concat(unquotedClassWithProp, " ");
|
|
246
246
|
}
|
|
247
247
|
});
|
|
248
248
|
return projectCustomCSSClassesData;
|
|
@@ -253,18 +253,18 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
|
|
|
253
253
|
var contentList = (_a = expression
|
|
254
254
|
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
255
255
|
contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
|
|
256
|
-
var needle = "{{"
|
|
256
|
+
var needle = "{{".concat(prop, "}}");
|
|
257
257
|
var dataOfItem = "";
|
|
258
258
|
if (prop.includes("current_user")) {
|
|
259
259
|
prop = prop.replace("current_user.", "");
|
|
260
260
|
if (Object.keys(user).length > 0) {
|
|
261
|
-
dataOfItem = exports.parseValueFromData(user, prop);
|
|
261
|
+
dataOfItem = (0, exports.parseValueFromData)(user, prop);
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
else if (prop.includes("current_tenant")) {
|
|
265
265
|
prop = prop.replace("current_tenant.", "");
|
|
266
266
|
if (Object.keys(tenant).length > 0) {
|
|
267
|
-
dataOfItem = exports.parseValueFromData(tenant, prop);
|
|
267
|
+
dataOfItem = (0, exports.parseValueFromData)(tenant, prop);
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
else if (prop.includes("current_session")) {
|
|
@@ -290,7 +290,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
|
|
|
290
290
|
}
|
|
291
291
|
else {
|
|
292
292
|
if (Object.keys(data).length > 0) {
|
|
293
|
-
dataOfItem = exports.parseValueFromData(data, prop);
|
|
293
|
+
dataOfItem = (0, exports.parseValueFromData)(data, prop);
|
|
294
294
|
//TODO: Need better way
|
|
295
295
|
delete data[prop];
|
|
296
296
|
}
|
|
@@ -390,7 +390,7 @@ var replaceTransferObjectValueIntoExpression = function (expression, transferObj
|
|
|
390
390
|
var contentList = (_a = expression
|
|
391
391
|
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
392
392
|
contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
|
|
393
|
-
var needle = "{{"
|
|
393
|
+
var needle = "{{".concat(prop, "}}");
|
|
394
394
|
var dataOfItem = "";
|
|
395
395
|
dataOfItem = transferObject[prop] ? transferObject[prop] : "";
|
|
396
396
|
expression = dataOfItem
|
|
@@ -38,10 +38,10 @@ var nextGeneratedString = function (str, prepend, minLength, append, algorithm)
|
|
|
38
38
|
finalValue = voca_1.default.padLeft(finalValue, minLength, "0");
|
|
39
39
|
}
|
|
40
40
|
if (prepend) {
|
|
41
|
-
finalValue = ""
|
|
41
|
+
finalValue = "".concat(prepend).concat(finalValue);
|
|
42
42
|
}
|
|
43
43
|
if (append) {
|
|
44
|
-
finalValue = ""
|
|
44
|
+
finalValue = "".concat(finalValue).concat(append);
|
|
45
45
|
}
|
|
46
46
|
return finalValue;
|
|
47
47
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"@types/voca": "^1.4.2",
|
|
32
32
|
"aws-sdk": "^2.1324.0",
|
|
33
33
|
"axios": "^1.1.2",
|
|
34
|
-
"drapcode-constant": "^1.2.
|
|
35
|
-
"drapcode-logger": "^1.0.
|
|
36
|
-
"drapcode-redis": "^1.0.
|
|
34
|
+
"drapcode-constant": "^1.2.3",
|
|
35
|
+
"drapcode-logger": "^1.0.3",
|
|
36
|
+
"drapcode-redis": "^1.0.3",
|
|
37
37
|
"express": "^4.17.1",
|
|
38
38
|
"express-rate-limit": "^5.1.3",
|
|
39
39
|
"express-validator": "^6.6.1",
|