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,10 +1,10 @@
|
|
|
1
|
-
export declare const getSearchObjQuery: (searchObj: any, searchQueryTypeObj: any
|
|
1
|
+
export declare const getSearchObjQuery: (searchObj: any, searchQueryTypeObj: any) => {
|
|
2
2
|
searchAggregateQuery: any;
|
|
3
3
|
likeQuery: any;
|
|
4
4
|
};
|
|
5
5
|
export declare const mongoSelectQuery: (query?: any) => any;
|
|
6
6
|
export declare const modifyQuery: (obj?: {}, hasAndQueryConjunction?: boolean) => any[];
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const isItDate: (queryValue: string) => RegExpMatchArray | null;
|
|
8
8
|
export declare const getMinMaxValue: (value: any) => {
|
|
9
9
|
startValue: any;
|
|
10
10
|
endValue: any;
|
|
@@ -1,196 +1,183 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getValueOfProjectConstant = exports.isFixedValueQuery = exports.getMinMaxValue = exports.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.entries(searchObj).forEach(
|
|
20
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
21
|
-
var key = _a[0], value = _a[1];
|
|
3
|
+
exports.getValueOfProjectConstant = exports.isFixedValueQuery = exports.getMinMaxValue = exports.isItDate = exports.modifyQuery = exports.mongoSelectQuery = exports.getSearchObjQuery = void 0;
|
|
4
|
+
const drapcode_constant_1 = require("drapcode-constant");
|
|
5
|
+
const date_util_1 = require("./date-util");
|
|
6
|
+
const util_1 = require("./util");
|
|
7
|
+
const getSearchObjQuery = (searchObj, searchQueryTypeObj) => {
|
|
8
|
+
let searchAggregateQuery = [];
|
|
9
|
+
let likeQuery = [];
|
|
10
|
+
Object.entries(searchObj).forEach(([key, value]) => {
|
|
22
11
|
if (value) {
|
|
23
|
-
|
|
12
|
+
const searchQueryTypeKey = searchQueryTypeObj[key];
|
|
24
13
|
if (searchQueryTypeKey) {
|
|
25
14
|
if (searchQueryTypeKey === "boolean") {
|
|
26
15
|
// if input is string and db field type is boolean
|
|
27
16
|
searchAggregateQuery.push({
|
|
28
|
-
$addFields:
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
$addFields: {
|
|
18
|
+
[`_${key}`]: `$${key}`,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
likeQuery.push({
|
|
22
|
+
[`_${key}`]: toBoolean(value),
|
|
31
23
|
});
|
|
32
|
-
likeQuery.push((_c = {},
|
|
33
|
-
_c["_".concat(key)] = toBoolean(value),
|
|
34
|
-
_c));
|
|
35
24
|
}
|
|
36
|
-
else if (
|
|
25
|
+
else if ([...drapcode_constant_1.OptionTypeFields, ...drapcode_constant_1.BelongsToReferenceField].includes(searchQueryTypeKey) //TODO: Changes
|
|
26
|
+
) {
|
|
37
27
|
// if input is string and db field type is array
|
|
38
28
|
searchAggregateQuery.push({
|
|
39
|
-
$addFields:
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
$addFields: {
|
|
30
|
+
[`_${key}`]: `$${key}`,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
likeQuery.push({
|
|
34
|
+
[`_${key}`]: { $all: [value] },
|
|
42
35
|
});
|
|
43
|
-
likeQuery.push((_e = {},
|
|
44
|
-
_e["_".concat(key)] = { $all: [value] },
|
|
45
|
-
_e));
|
|
46
36
|
}
|
|
47
37
|
else if (searchQueryTypeKey === "tel") {
|
|
48
38
|
// handling value when db field type is tel
|
|
49
39
|
searchAggregateQuery.push({
|
|
50
|
-
$addFields:
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
$addFields: {
|
|
41
|
+
[`_${key}`]: { $toString: `$${key}` },
|
|
42
|
+
},
|
|
53
43
|
});
|
|
54
|
-
likeQuery.push(
|
|
55
|
-
|
|
44
|
+
likeQuery.push({
|
|
45
|
+
[`_${key}`]: {
|
|
56
46
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
57
47
|
$options: "i",
|
|
58
48
|
},
|
|
59
|
-
|
|
49
|
+
});
|
|
60
50
|
}
|
|
61
51
|
else if (searchQueryTypeKey === "number") {
|
|
62
52
|
if (key.startsWith("min_") || key.startsWith("max_")) {
|
|
63
|
-
|
|
53
|
+
let fieldKey = key.replace("min_", "");
|
|
64
54
|
fieldKey = fieldKey.replace("max_", "");
|
|
65
|
-
|
|
55
|
+
const numericValue = Number(value);
|
|
66
56
|
if (key.startsWith("min_")) {
|
|
67
|
-
likeQuery.push(
|
|
57
|
+
likeQuery.push({ [`${fieldKey}`]: { $gte: numericValue } });
|
|
68
58
|
}
|
|
69
59
|
else if (key.startsWith("max_")) {
|
|
70
|
-
likeQuery.push(
|
|
60
|
+
likeQuery.push({ [`${fieldKey}`]: { $lte: numericValue } });
|
|
71
61
|
}
|
|
72
62
|
}
|
|
73
63
|
else {
|
|
74
64
|
// handling value when db field type is Double/Int
|
|
75
65
|
searchAggregateQuery.push({
|
|
76
|
-
$addFields:
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
$addFields: {
|
|
67
|
+
[`_${key}`]: { $toString: { $toLong: `$${key}` } },
|
|
68
|
+
},
|
|
79
69
|
});
|
|
80
|
-
likeQuery.push(
|
|
81
|
-
|
|
70
|
+
likeQuery.push({
|
|
71
|
+
[`_${key}`]: {
|
|
82
72
|
$regex: value,
|
|
83
73
|
$options: "i",
|
|
84
74
|
},
|
|
85
|
-
|
|
75
|
+
});
|
|
86
76
|
}
|
|
87
77
|
}
|
|
88
|
-
else if (
|
|
89
|
-
drapcode_constant_1.FieldTypes.date.id
|
|
90
|
-
|
|
78
|
+
else if ([
|
|
79
|
+
drapcode_constant_1.FieldTypes.date.id,
|
|
80
|
+
...drapcode_constant_1.systemDateField,
|
|
91
81
|
drapcode_constant_1.FieldTypes.time_slot.id,
|
|
92
|
-
]
|
|
82
|
+
].includes(searchQueryTypeKey)) {
|
|
93
83
|
if (key.startsWith("start_") || key.startsWith("end_")) {
|
|
94
|
-
|
|
84
|
+
let fieldKey = key.replace("start_", "");
|
|
95
85
|
fieldKey = fieldKey.replace("end_", "");
|
|
96
86
|
searchAggregateQuery.push({
|
|
97
|
-
$addFields:
|
|
98
|
-
|
|
99
|
-
|
|
87
|
+
$addFields: {
|
|
88
|
+
[`_${key}`]: { $toString: `$${fieldKey}` },
|
|
89
|
+
},
|
|
100
90
|
});
|
|
101
91
|
if (key.startsWith("start_")) {
|
|
102
|
-
likeQuery.push(
|
|
103
|
-
|
|
92
|
+
likeQuery.push({
|
|
93
|
+
[`_${key}`]: {
|
|
104
94
|
$gte: (0, date_util_1.timezoneDateParse)(value, false, true),
|
|
105
95
|
},
|
|
106
|
-
|
|
96
|
+
});
|
|
107
97
|
}
|
|
108
98
|
else if (key.startsWith("end_")) {
|
|
109
|
-
likeQuery.push(
|
|
110
|
-
|
|
99
|
+
likeQuery.push({
|
|
100
|
+
[`_${key}`]: {
|
|
111
101
|
$lt: (0, date_util_1.timezoneDateParse)(value),
|
|
112
102
|
},
|
|
113
|
-
|
|
103
|
+
});
|
|
114
104
|
}
|
|
115
105
|
}
|
|
116
106
|
else {
|
|
117
107
|
searchAggregateQuery.push({
|
|
118
|
-
$addFields:
|
|
119
|
-
|
|
120
|
-
|
|
108
|
+
$addFields: {
|
|
109
|
+
[`_${key}`]: { $toString: `$${key}` },
|
|
110
|
+
},
|
|
121
111
|
});
|
|
122
|
-
likeQuery.push(
|
|
123
|
-
|
|
112
|
+
likeQuery.push({
|
|
113
|
+
[`_${key}`]: {
|
|
124
114
|
$gte: (0, date_util_1.timezoneDateParse)(value, false, true),
|
|
125
115
|
},
|
|
126
|
-
|
|
127
|
-
likeQuery.push(
|
|
128
|
-
|
|
116
|
+
});
|
|
117
|
+
likeQuery.push({
|
|
118
|
+
[`_${key}`]: {
|
|
129
119
|
$lt: (0, date_util_1.timezoneDateParse)(value, false),
|
|
130
120
|
},
|
|
131
|
-
|
|
121
|
+
});
|
|
132
122
|
}
|
|
133
123
|
}
|
|
134
124
|
else {
|
|
135
125
|
// if input is string and db field type is number
|
|
136
126
|
// converting db field to string first
|
|
137
127
|
searchAggregateQuery.push({
|
|
138
|
-
$addFields:
|
|
139
|
-
|
|
140
|
-
|
|
128
|
+
$addFields: {
|
|
129
|
+
[`_${key}`]: { $toString: `$${key}` },
|
|
130
|
+
},
|
|
141
131
|
});
|
|
142
|
-
likeQuery.push(
|
|
143
|
-
|
|
132
|
+
likeQuery.push({
|
|
133
|
+
[`_${key}`]: {
|
|
144
134
|
$regex: value,
|
|
145
135
|
$options: "i",
|
|
146
136
|
},
|
|
147
|
-
|
|
137
|
+
});
|
|
148
138
|
}
|
|
149
139
|
}
|
|
150
140
|
else {
|
|
151
|
-
likeQuery.push(
|
|
152
|
-
|
|
141
|
+
likeQuery.push({
|
|
142
|
+
[key]: {
|
|
153
143
|
$regex: value,
|
|
154
144
|
$options: "i",
|
|
155
145
|
},
|
|
156
|
-
|
|
146
|
+
});
|
|
157
147
|
}
|
|
158
148
|
}
|
|
159
149
|
});
|
|
160
|
-
console.log(
|
|
161
|
-
console.log(
|
|
162
|
-
return { searchAggregateQuery
|
|
150
|
+
console.log(`==> searchAggregateQuery`, JSON.stringify(searchAggregateQuery));
|
|
151
|
+
console.log(`==> likeQuery`, JSON.stringify(likeQuery));
|
|
152
|
+
return { searchAggregateQuery, likeQuery };
|
|
163
153
|
};
|
|
164
154
|
exports.getSearchObjQuery = getSearchObjQuery;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
var fieldsInclude = query.fieldsInclude, fieldsExclude = query.fieldsExclude, finder = query.finder;
|
|
155
|
+
const mongoSelectQuery = (query = {}) => {
|
|
156
|
+
const projection = {};
|
|
157
|
+
let { fieldsInclude, fieldsExclude, finder } = query;
|
|
169
158
|
if (!fieldsExclude)
|
|
170
159
|
fieldsExclude = [];
|
|
171
160
|
if (fieldsInclude[0] === "*") {
|
|
172
|
-
fieldsExclude.map(
|
|
161
|
+
fieldsExclude.map((field) => {
|
|
173
162
|
if (field)
|
|
174
|
-
return (projection[
|
|
163
|
+
return (projection[`${field}`] = 0);
|
|
175
164
|
});
|
|
176
165
|
}
|
|
177
166
|
else {
|
|
178
167
|
if (["FIND_ALL", "FIND"].includes(finder))
|
|
179
168
|
fieldsInclude = (0, util_1.processFieldsInclude)(fieldsInclude);
|
|
180
|
-
fieldsInclude.map(
|
|
169
|
+
fieldsInclude.map((field) => {
|
|
181
170
|
if (field)
|
|
182
|
-
return (projection[
|
|
171
|
+
return (projection[`${field}`] = 1);
|
|
183
172
|
});
|
|
184
173
|
}
|
|
185
174
|
return projection;
|
|
186
175
|
};
|
|
187
176
|
exports.mongoSelectQuery = mongoSelectQuery;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
Object.entries(obj).forEach(function (_a) {
|
|
193
|
-
var key = _a[0], value = _a[1];
|
|
177
|
+
const modifyQuery = (obj = {}, hasAndQueryConjunction = false) => {
|
|
178
|
+
let arr = [];
|
|
179
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
180
|
+
console.log("key:>> ", key);
|
|
194
181
|
if (hasAndQueryConjunction) {
|
|
195
182
|
arr.push({ $and: value });
|
|
196
183
|
}
|
|
@@ -201,7 +188,7 @@ var modifyQuery = function (obj, hasAndQueryConjunction) {
|
|
|
201
188
|
return arr;
|
|
202
189
|
};
|
|
203
190
|
exports.modifyQuery = modifyQuery;
|
|
204
|
-
|
|
191
|
+
const toBoolean = (value) => {
|
|
205
192
|
if (!value) {
|
|
206
193
|
return false;
|
|
207
194
|
}
|
|
@@ -215,33 +202,33 @@ var toBoolean = function (value) {
|
|
|
215
202
|
return false;
|
|
216
203
|
}
|
|
217
204
|
};
|
|
218
|
-
|
|
205
|
+
const isItDate = (queryValue) => {
|
|
219
206
|
return ("" + queryValue).match(date_util_1.DATE_REGEX);
|
|
220
207
|
};
|
|
221
|
-
exports.
|
|
222
|
-
|
|
223
|
-
|
|
208
|
+
exports.isItDate = isItDate;
|
|
209
|
+
const getMinMaxValue = (value) => {
|
|
210
|
+
let isFixedValue = (0, exports.isFixedValueQuery)(value);
|
|
224
211
|
if (isFixedValue)
|
|
225
212
|
value = value.replace("FIXED_VALUE::", "");
|
|
226
|
-
|
|
213
|
+
let isValid = value && value.includes("---");
|
|
227
214
|
if (isValid) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
215
|
+
let isInteger = value.includes("^");
|
|
216
|
+
let result = value.split("---");
|
|
217
|
+
let endValue = result[1];
|
|
231
218
|
if (isInteger && result.length)
|
|
232
219
|
endValue = endValue.slice(0, -1);
|
|
233
|
-
return { startValue: result[0], endValue
|
|
220
|
+
return { startValue: result[0], endValue, isInteger, isFixedValue };
|
|
234
221
|
}
|
|
235
222
|
else {
|
|
236
|
-
return { startValue: "", endValue: "", isFixedValue
|
|
223
|
+
return { startValue: "", endValue: "", isFixedValue };
|
|
237
224
|
}
|
|
238
225
|
};
|
|
239
226
|
exports.getMinMaxValue = getMinMaxValue;
|
|
240
227
|
// TODO: can be refactor with entity condition
|
|
241
|
-
|
|
242
|
-
|
|
228
|
+
const isFixedValueQuery = (value) => {
|
|
229
|
+
let isFixeValue = false;
|
|
243
230
|
if (value && Array.isArray(value)) {
|
|
244
|
-
value.forEach(
|
|
231
|
+
value.forEach((val) => {
|
|
245
232
|
if (typeof val === "string" || val instanceof String)
|
|
246
233
|
isFixeValue = val.startsWith("FIXED_VALUE::");
|
|
247
234
|
});
|
|
@@ -253,18 +240,18 @@ var isFixedValueQuery = function (value) {
|
|
|
253
240
|
return isFixeValue;
|
|
254
241
|
};
|
|
255
242
|
exports.isFixedValueQuery = isFixedValueQuery;
|
|
256
|
-
|
|
243
|
+
const getValueOfProjectConstant = (value, currentUser, timezone) => {
|
|
257
244
|
if (!timezone)
|
|
258
245
|
timezone = "(GMT+5:30)";
|
|
259
246
|
timezone = timezone.substring(4, 10);
|
|
260
|
-
|
|
247
|
+
let result;
|
|
261
248
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
262
|
-
return currentUser[
|
|
249
|
+
return currentUser[`uuid`];
|
|
263
250
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
264
251
|
result = (0, date_util_1.createLoggerDateFormat)(timezone);
|
|
265
252
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
266
253
|
result = (0, date_util_1.createLogsDateFormat)(timezone);
|
|
267
|
-
if (drapcode_constant_1.DateTimeUnit.some(
|
|
254
|
+
if (drapcode_constant_1.DateTimeUnit.some((cnst) => value.includes(cnst)))
|
|
268
255
|
result = (0, date_util_1.getDateValue)(value, timezone);
|
|
269
256
|
return result;
|
|
270
257
|
};
|