drapcode-utility 1.0.0 → 1.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/errors/app-error.js +2 -0
- package/build/errors/axios-error.d.ts +0 -3
- package/build/errors/axios-error.js +1 -48
- 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/format-fields/index.d.ts +1 -0
- package/build/format-fields/index.js +68 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/utils/check-error.js +12 -7
- package/build/utils/date-util.d.ts +3 -3
- package/build/utils/date-util.js +24 -10
- package/build/utils/query-parser.js +44 -27
- package/build/utils/query-paser-new.js +6 -16
- package/build/utils/util.js +2 -0
- package/package.json +1 -1
|
@@ -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 __());
|
|
@@ -8,6 +8,3 @@ export declare const parseAxiosError: (error: AxiosError) => {
|
|
|
8
8
|
error: any;
|
|
9
9
|
status: number;
|
|
10
10
|
};
|
|
11
|
-
export declare const parseXanoConfigError: (error: any) => string;
|
|
12
|
-
export declare const parseAirtableConfigError: (error: any) => string;
|
|
13
|
-
export declare const parseSupabaseConfigError: (error: any) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parseAxiosError = void 0;
|
|
4
4
|
var parseAxiosError = function (error) {
|
|
5
5
|
if (!error) {
|
|
6
6
|
return {};
|
|
@@ -29,50 +29,3 @@ var parseAxiosError = function (error) {
|
|
|
29
29
|
return { success: false, error: errData, status: errStatus };
|
|
30
30
|
};
|
|
31
31
|
exports.parseAxiosError = parseAxiosError;
|
|
32
|
-
var parseXanoConfigError = function (error) {
|
|
33
|
-
if (!error || !error.code) {
|
|
34
|
-
return "Failed from Xano";
|
|
35
|
-
}
|
|
36
|
-
var errorMessage = "";
|
|
37
|
-
switch (error.code) {
|
|
38
|
-
case "ERROR_CODE_UNAUTHORIZED":
|
|
39
|
-
errorMessage = "Developer API Key is wrong";
|
|
40
|
-
break;
|
|
41
|
-
default:
|
|
42
|
-
errorMessage = "Failed from Xano";
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
return errorMessage;
|
|
46
|
-
};
|
|
47
|
-
exports.parseXanoConfigError = parseXanoConfigError;
|
|
48
|
-
var parseAirtableConfigError = function (error) {
|
|
49
|
-
if (!error || !error.error || !error.error.type) {
|
|
50
|
-
return "Failed from Airtable";
|
|
51
|
-
}
|
|
52
|
-
var errorMessage = "";
|
|
53
|
-
switch (error.error.type) {
|
|
54
|
-
case "AUTHENTICATION_REQUIRED":
|
|
55
|
-
errorMessage = "Authorization is missing/wrong.";
|
|
56
|
-
break;
|
|
57
|
-
default:
|
|
58
|
-
errorMessage = "Failed from Airtable";
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
return errorMessage;
|
|
62
|
-
};
|
|
63
|
-
exports.parseAirtableConfigError = parseAirtableConfigError;
|
|
64
|
-
var parseSupabaseConfigError = function (error) {
|
|
65
|
-
if (!error) {
|
|
66
|
-
return "Failed from Supabase";
|
|
67
|
-
}
|
|
68
|
-
var errorMessage = "";
|
|
69
|
-
switch (error) {
|
|
70
|
-
case "ENOTFOUND":
|
|
71
|
-
errorMessage = "Given Supabase URL does not exists/API Key is wrong";
|
|
72
|
-
break;
|
|
73
|
-
default:
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
return errorMessage;
|
|
77
|
-
};
|
|
78
|
-
exports.parseSupabaseConfigError = parseSupabaseConfigError;
|
|
@@ -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 __());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatFieldsOfItem: (item: any, fields: any) => any;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatFieldsOfItem = void 0;
|
|
4
|
+
var drapcode_constant_1 = require("drapcode-constant");
|
|
5
|
+
var formatFieldsOfItem = function (item, fields) {
|
|
6
|
+
if (!item)
|
|
7
|
+
return item;
|
|
8
|
+
if (!fields && !fields.length)
|
|
9
|
+
return item;
|
|
10
|
+
if (Array.isArray(item)) {
|
|
11
|
+
item = item.map(function (itemData) { return formatField(itemData, fields); });
|
|
12
|
+
}
|
|
13
|
+
else
|
|
14
|
+
item = formatField(item, fields);
|
|
15
|
+
return item;
|
|
16
|
+
};
|
|
17
|
+
exports.formatFieldsOfItem = formatFieldsOfItem;
|
|
18
|
+
var formatField = function (itemData, fields) {
|
|
19
|
+
var newItemData = {};
|
|
20
|
+
Object.keys(itemData).forEach(function (key) {
|
|
21
|
+
var field = fields.find(function (field) { return field.fieldName === key; });
|
|
22
|
+
newItemData[key] = field
|
|
23
|
+
? getFormatFieldData(itemData[key], field.type)
|
|
24
|
+
: itemData[key];
|
|
25
|
+
});
|
|
26
|
+
return newItemData;
|
|
27
|
+
};
|
|
28
|
+
var getFormatFieldData = function (fieldData, fieldType) {
|
|
29
|
+
var createdAt = drapcode_constant_1.FieldTypes.createdAt, text = drapcode_constant_1.FieldTypes.text, large_text = drapcode_constant_1.FieldTypes.large_text, date = drapcode_constant_1.FieldTypes.date, password = drapcode_constant_1.FieldTypes.password, uuid = drapcode_constant_1.FieldTypes.uuid, custom_uuid = drapcode_constant_1.FieldTypes.custom_uuid, email = drapcode_constant_1.FieldTypes.email, url = drapcode_constant_1.FieldTypes.url, number = drapcode_constant_1.FieldTypes.number, unix_timestamp = drapcode_constant_1.FieldTypes.unix_timestamp, reference = drapcode_constant_1.FieldTypes.reference, belongsTo = drapcode_constant_1.FieldTypes.belongsTo, multi_reference = drapcode_constant_1.FieldTypes.multi_reference, dynamic_option = drapcode_constant_1.FieldTypes.dynamic_option, static_option = drapcode_constant_1.FieldTypes.static_option, boolean = drapcode_constant_1.FieldTypes.boolean, time_slot = drapcode_constant_1.FieldTypes.time_slot;
|
|
30
|
+
var stringType = [
|
|
31
|
+
createdAt.id,
|
|
32
|
+
text.id,
|
|
33
|
+
large_text.id,
|
|
34
|
+
date.id,
|
|
35
|
+
password.id,
|
|
36
|
+
uuid.id,
|
|
37
|
+
custom_uuid.id,
|
|
38
|
+
email.id,
|
|
39
|
+
url.id,
|
|
40
|
+
time_slot.id,
|
|
41
|
+
];
|
|
42
|
+
var numberType = [number.id, unix_timestamp.id];
|
|
43
|
+
var arrayType = [
|
|
44
|
+
reference.id,
|
|
45
|
+
belongsTo.id,
|
|
46
|
+
multi_reference.id,
|
|
47
|
+
dynamic_option.id,
|
|
48
|
+
static_option.id,
|
|
49
|
+
];
|
|
50
|
+
if (stringType.includes(fieldType)) {
|
|
51
|
+
if (typeof fieldData !== "string")
|
|
52
|
+
fieldData = String(fieldData);
|
|
53
|
+
}
|
|
54
|
+
if (numberType.includes(fieldType)) {
|
|
55
|
+
if (typeof fieldData !== "number")
|
|
56
|
+
fieldData = Number(fieldData);
|
|
57
|
+
}
|
|
58
|
+
if (fieldType === boolean.id) {
|
|
59
|
+
if (typeof fieldData !== "boolean")
|
|
60
|
+
fieldData = Boolean(fieldData);
|
|
61
|
+
}
|
|
62
|
+
if (arrayType.includes(fieldType)) {
|
|
63
|
+
if (!Array.isArray(fieldData)) {
|
|
64
|
+
fieldData = fieldData ? [fieldData] : [];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return fieldData;
|
|
68
|
+
};
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -27,3 +27,4 @@ __exportStar(require("./utils/uuid-generator"), exports);
|
|
|
27
27
|
__exportStar(require("./utils/check-error"), exports);
|
|
28
28
|
__exportStar(require("./utils/prepare-query"), exports);
|
|
29
29
|
__exportStar(require("./encryption/index"), exports);
|
|
30
|
+
__exportStar(require("./format-fields/index"), exports);
|
|
@@ -35,12 +35,10 @@ 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
|
-
for (var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
r[k] = a[j];
|
|
43
|
-
return r;
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
39
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
40
|
+
to[j] = from[i];
|
|
41
|
+
return to;
|
|
44
42
|
};
|
|
45
43
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
44
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -119,6 +117,7 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
119
117
|
console.log("handleMultErrorConfig result :>> " + Object.keys(result));
|
|
120
118
|
apiErrorMessage = lodash_1.default.get(result, message);
|
|
121
119
|
if (apiErrorMessage) {
|
|
120
|
+
console.log("*** utility 3 ***");
|
|
122
121
|
if (typeof apiErrorMessage == "string") {
|
|
123
122
|
console.log("It's string so leave");
|
|
124
123
|
}
|
|
@@ -135,13 +134,16 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
135
134
|
apiErrorValue = lodash_1.default.get(result, path);
|
|
136
135
|
}
|
|
137
136
|
else {
|
|
137
|
+
console.log("*** utility 7 ***");
|
|
138
138
|
apiErrorValue = status;
|
|
139
139
|
}
|
|
140
|
+
console.log("*** utility 8 ***");
|
|
140
141
|
}
|
|
141
142
|
else {
|
|
142
143
|
console.log("result", result);
|
|
143
144
|
apiErrorValue = status;
|
|
144
145
|
}
|
|
146
|
+
console.log("apiErrorValue", apiErrorValue);
|
|
145
147
|
apiErrorValue = "" + apiErrorValue;
|
|
146
148
|
console.log("apiErrorMessage", apiErrorMessage);
|
|
147
149
|
console.log("apiErrorValue", apiErrorValue);
|
|
@@ -152,6 +154,7 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
152
154
|
};
|
|
153
155
|
}
|
|
154
156
|
else if (["false", "error", "fail", "failed"].includes(apiErrorValue.toLowerCase())) {
|
|
157
|
+
console.log("*** utility 9 ***");
|
|
155
158
|
return {
|
|
156
159
|
status: 400,
|
|
157
160
|
message: apiErrorMessage,
|
|
@@ -160,6 +163,8 @@ var handleMultErrorConfig = function (error, result, status) {
|
|
|
160
163
|
else if (voca_1.default.startsWith(apiErrorValue, "3") ||
|
|
161
164
|
voca_1.default.startsWith(apiErrorValue, "4") ||
|
|
162
165
|
voca_1.default.startsWith(apiErrorValue, "5")) {
|
|
166
|
+
console.log("*** utility 10 ***");
|
|
167
|
+
console.log("Compare 4");
|
|
163
168
|
return {
|
|
164
169
|
status: apiErrorValue,
|
|
165
170
|
message: apiErrorMessage,
|
|
@@ -176,7 +181,7 @@ var nestedValue = function (data, messages) {
|
|
|
176
181
|
messages.push(value);
|
|
177
182
|
}
|
|
178
183
|
else if (Array.isArray(value)) {
|
|
179
|
-
messages =
|
|
184
|
+
messages = __spreadArray(__spreadArray([], messages), value);
|
|
180
185
|
}
|
|
181
186
|
else {
|
|
182
187
|
if (Object.keys(value).length) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const DATE_REGEX: RegExp;
|
|
2
|
-
export declare const createLoggerDateFormat: () => any;
|
|
2
|
+
export declare const createLoggerDateFormat: (timezone?: string) => any;
|
|
3
3
|
export declare const createLoggerPreviouseDateFormat: () => any;
|
|
4
|
-
export declare const createLogsDateFormat: () => any;
|
|
5
|
-
export declare const getDateValue: (value: string) => any;
|
|
4
|
+
export declare const createLogsDateFormat: (timezone?: string) => any;
|
|
5
|
+
export declare const getDateValue: (value: string, timezone?: string) => any;
|
|
6
6
|
export declare const nextDayDate: (date: any) => any;
|
|
7
7
|
export declare const timezoneDateParse: (value: string, nextDay?: boolean, prevDay?: boolean) => Date;
|
|
8
8
|
export declare const formatProjectDates: (item: any, dateFormat: string, fields: Array<object>, reverse: boolean) => any;
|
package/build/utils/date-util.js
CHANGED
|
@@ -4,32 +4,46 @@ exports.formatProjectDates = exports.timezoneDateParse = exports.nextDayDate = e
|
|
|
4
4
|
var drapcode_constant_1 = require("drapcode-constant");
|
|
5
5
|
var moment = require("moment");
|
|
6
6
|
exports.DATE_REGEX = /^[12]\d{3}(-(0[1-9]|1[0-2])(-(0[1-9]|[12][0-9]|3[01]))?)(T| )?(([01][0-9]|2[0-3]):[0-5]\d(:[0-5]\d(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
7
|
-
var createLoggerDateFormat = function () {
|
|
8
|
-
|
|
7
|
+
var createLoggerDateFormat = function (timezone) {
|
|
8
|
+
if (timezone === void 0) { timezone = ""; }
|
|
9
|
+
var result = moment();
|
|
10
|
+
console.log("\n result 1 :>> ", result);
|
|
11
|
+
result = timezone ? result.utcOffset(timezone) : result;
|
|
12
|
+
console.log("\n result 2 :>> ", result);
|
|
13
|
+
return result.format("YYYY-MM-DD");
|
|
9
14
|
};
|
|
10
15
|
exports.createLoggerDateFormat = createLoggerDateFormat;
|
|
11
16
|
var createLoggerPreviouseDateFormat = function () {
|
|
12
17
|
return moment().subtract(10, "days").format("YYYY-MM-DD");
|
|
13
18
|
};
|
|
14
19
|
exports.createLoggerPreviouseDateFormat = createLoggerPreviouseDateFormat;
|
|
15
|
-
var createLogsDateFormat = function () {
|
|
16
|
-
|
|
20
|
+
var createLogsDateFormat = function (timezone) {
|
|
21
|
+
if (timezone === void 0) { timezone = ""; }
|
|
22
|
+
var result = moment();
|
|
23
|
+
console.log("\n result 1 :>> ", result);
|
|
24
|
+
result = timezone ? result.utcOffset(timezone) : result;
|
|
25
|
+
console.log("\n result 2 :>> ", result);
|
|
26
|
+
return result.format("YYYY-MM-DDTHH:mm:ss.SSS");
|
|
17
27
|
};
|
|
18
28
|
exports.createLogsDateFormat = createLogsDateFormat;
|
|
19
|
-
var getDateValue = function (value) {
|
|
29
|
+
var getDateValue = function (value, timezone) {
|
|
30
|
+
if (timezone === void 0) { timezone = ""; }
|
|
20
31
|
if (!value)
|
|
21
|
-
return exports.createLogsDateFormat();
|
|
32
|
+
return exports.createLogsDateFormat(timezone);
|
|
22
33
|
var dateFormat = "YYYY-MM-DDTHH:mm:ss.SSS";
|
|
23
34
|
var _a = value.split(":"), type = _a[0], number = _a[1], unit = _a[2];
|
|
35
|
+
if (!["ADD", "SUB"].includes(type))
|
|
36
|
+
return exports.createLogsDateFormat(timezone);
|
|
24
37
|
var dateUnit = getDateUnit(unit);
|
|
38
|
+
var result;
|
|
25
39
|
if (type === "ADD") {
|
|
26
|
-
|
|
40
|
+
result = moment().add(number, dateUnit);
|
|
27
41
|
}
|
|
28
42
|
else if (type === "SUB") {
|
|
29
|
-
|
|
43
|
+
result = moment().subtract(number, dateUnit);
|
|
30
44
|
}
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
result = timezone ? result.utcOffset(timezone) : result;
|
|
46
|
+
return result.format(dateFormat);
|
|
33
47
|
};
|
|
34
48
|
exports.getDateValue = getDateValue;
|
|
35
49
|
var getDateUnit = function (unit) {
|
|
@@ -35,12 +35,10 @@ 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
|
-
for (var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
r[k] = a[j];
|
|
43
|
-
return r;
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
39
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
40
|
+
to[j] = from[i];
|
|
41
|
+
return to;
|
|
44
42
|
};
|
|
45
43
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
44
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -68,10 +66,17 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
68
66
|
if (!query)
|
|
69
67
|
return [2 /*return*/, ""];
|
|
70
68
|
console.log("***1*** queryParser ***");
|
|
71
|
-
|
|
72
|
-
console.log("
|
|
69
|
+
console.log("%%%%% refCollectionFieldsInItems", JSON.stringify(refCollectionFieldsInItems));
|
|
70
|
+
console.log("%%%% timezone", timezone);
|
|
71
|
+
console.log("collectionName", collectionName);
|
|
72
|
+
console.log("query", JSON.stringify(query));
|
|
73
|
+
console.log("constants", JSON.stringify(constants));
|
|
74
|
+
console.log("externalParams", JSON.stringify(externalParams));
|
|
75
|
+
console.log("currentUser", JSON.stringify(currentUser));
|
|
76
|
+
console.log("searchObj", JSON.stringify(searchObj));
|
|
77
|
+
console.log("searchQueryTypeObj", JSON.stringify(searchQueryTypeObj));
|
|
78
|
+
filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant, timezone);
|
|
73
79
|
console.log("filterQuery", JSON.stringify(filterQuery));
|
|
74
|
-
console.log("==> searchQueryTypeObj :>>", searchQueryTypeObj);
|
|
75
80
|
aggregateQuery = [];
|
|
76
81
|
queryStr = ".aggregate([])";
|
|
77
82
|
if (filterQuery.length &&
|
|
@@ -80,25 +85,31 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
80
85
|
searchQueryObj = null;
|
|
81
86
|
if (searchObj) {
|
|
82
87
|
_a = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
|
|
83
|
-
aggregateQuery =
|
|
88
|
+
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
|
|
89
|
+
console.log("likeQuery after getSearchObjQuery", JSON.stringify(likeQuery));
|
|
84
90
|
if (likeQuery && likeQuery.length > 0) {
|
|
85
91
|
searchQueryObj = likeQuery;
|
|
86
92
|
}
|
|
87
93
|
}
|
|
94
|
+
console.log("aggregateQuery After search object condition", JSON.stringify(aggregateQuery));
|
|
95
|
+
console.log("searchQueryObj", JSON.stringify(searchQueryObj));
|
|
88
96
|
finalQuery = { $and: filterQuery };
|
|
89
97
|
if (searchQueryObj) {
|
|
90
98
|
(_c = finalQuery.$and).push.apply(_c, searchQueryObj);
|
|
91
99
|
}
|
|
100
|
+
console.log("finalQuery after", JSON.stringify(finalQuery));
|
|
92
101
|
aggregateQuery.push({ $match: finalQuery });
|
|
93
102
|
}
|
|
94
103
|
else if (searchObj) {
|
|
104
|
+
console.log("I donot have filter query");
|
|
95
105
|
_b = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
|
|
96
|
-
aggregateQuery =
|
|
106
|
+
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
|
|
97
107
|
if (likeQuery.length) {
|
|
98
108
|
// aggregateQuery.push({ $match: { $or: likeQuery } });
|
|
99
109
|
aggregateQuery.push({ $match: { $and: likeQuery } });
|
|
100
110
|
}
|
|
101
111
|
}
|
|
112
|
+
console.log("aggregateQuery", JSON.stringify(aggregateQuery));
|
|
102
113
|
console.log("==> query", query);
|
|
103
114
|
projection = mongoSelectQuery(query);
|
|
104
115
|
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy;
|
|
@@ -210,6 +221,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
210
221
|
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
211
222
|
}
|
|
212
223
|
console.log("==> aggregateQuery", aggregateQuery);
|
|
224
|
+
console.log("==> aggregateQuery", JSON.stringify(aggregateQuery));
|
|
213
225
|
queryStr = ".aggregate(" + JSON.stringify(aggregateQuery) + ", { collation: { locale: \"en\" } })";
|
|
214
226
|
str = "req.db.collection('" + collectionName + "')" + queryStr;
|
|
215
227
|
str += ".toArray()";
|
|
@@ -233,7 +245,7 @@ var toBoolean = function (value) {
|
|
|
233
245
|
return false;
|
|
234
246
|
}
|
|
235
247
|
};
|
|
236
|
-
var mongoFilterQuery = function (query, externalParams, constants, currentUser, currentTenant) {
|
|
248
|
+
var mongoFilterQuery = function (query, externalParams, constants, currentUser, currentTenant, timezone) {
|
|
237
249
|
if (currentUser === void 0) { currentUser = {}; }
|
|
238
250
|
if (currentTenant === void 0) { currentTenant = {}; }
|
|
239
251
|
var filterQuery = { $or0: [] };
|
|
@@ -242,7 +254,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
|
|
|
242
254
|
conditions.forEach(function (queryObj, index) {
|
|
243
255
|
var query = queryObj.query, requiredExternal = queryObj.requiredExternal;
|
|
244
256
|
console.log("query :>> ", JSON.stringify(query));
|
|
245
|
-
var mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant);
|
|
257
|
+
var mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone);
|
|
246
258
|
console.log(":::::::::mongoQuery::::", JSON.stringify(mongoQuery));
|
|
247
259
|
queryConjunctions.push(queryObj.conjunctionType);
|
|
248
260
|
if (queryObj.conjunctionType == "OR") {
|
|
@@ -311,11 +323,11 @@ var modifyQuery = function (obj, hasAndQueryConjunction) {
|
|
|
311
323
|
console.log("🚀 ~ file: query-parser.ts:303 ~ Object.entries ~ arr:", arr);
|
|
312
324
|
return arr;
|
|
313
325
|
};
|
|
314
|
-
var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant) {
|
|
326
|
+
var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone) {
|
|
315
327
|
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;
|
|
316
328
|
if (currentUser === void 0) { currentUser = {}; }
|
|
317
329
|
if (currentTenant === void 0) { currentTenant = {}; }
|
|
318
|
-
var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant);
|
|
330
|
+
var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone);
|
|
319
331
|
if (["undefined", "null", null, undefined, ""].includes(fieldValue)) {
|
|
320
332
|
//TODO: In case field is not present in old record then fieldValue is undefined
|
|
321
333
|
//TODO: In case of this, we assign some random string to avoid resulting all values
|
|
@@ -327,8 +339,8 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
327
339
|
var isDate = checkDate(fieldValue);
|
|
328
340
|
console.log("isDate queryToMongo 2", isDate);
|
|
329
341
|
var key = query.key, field = query.field, value = query.value, fieldType = query.fieldType;
|
|
330
|
-
if
|
|
331
|
-
|
|
342
|
+
// Todo: Remove if it's working properly
|
|
343
|
+
// if (isDate) fieldValue = new Date(fieldValue);
|
|
332
344
|
console.log("fieldValue queryToMongo 1", fieldValue);
|
|
333
345
|
var condition = [
|
|
334
346
|
"dynamic_option",
|
|
@@ -458,7 +470,7 @@ var isEntityInCondition = function (value) {
|
|
|
458
470
|
return isEntity;
|
|
459
471
|
};
|
|
460
472
|
exports.isEntityInCondition = isEntityInCondition;
|
|
461
|
-
var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant) {
|
|
473
|
+
var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone) {
|
|
462
474
|
var key = query.key, value = query.value, fieldType = query.fieldType;
|
|
463
475
|
if (fieldType &&
|
|
464
476
|
!requiredExternal &&
|
|
@@ -490,16 +502,16 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
490
502
|
endValue_1 = "" + externalParams[endValue_1];
|
|
491
503
|
}
|
|
492
504
|
else {
|
|
493
|
-
if (
|
|
505
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
494
506
|
return startValue_1.includes(cnst);
|
|
495
507
|
})) {
|
|
496
|
-
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
|
|
508
|
+
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser, timezone);
|
|
497
509
|
}
|
|
498
510
|
else {
|
|
499
511
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
500
512
|
}
|
|
501
|
-
if (
|
|
502
|
-
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
|
|
513
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
514
|
+
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser, timezone);
|
|
503
515
|
}
|
|
504
516
|
else {
|
|
505
517
|
endValue_1 = constants.filter(function (constant) { return constant.name == endValue_1; });
|
|
@@ -611,7 +623,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
611
623
|
return currentTenant["uuid"];
|
|
612
624
|
}
|
|
613
625
|
if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
614
|
-
return getValueOfProjectConstant(value, {});
|
|
626
|
+
return getValueOfProjectConstant(value, {}, timezone);
|
|
615
627
|
}
|
|
616
628
|
if (exports.isEntityInCondition(value)) {
|
|
617
629
|
var key_1 = value.replace("ENTITY::", "");
|
|
@@ -647,15 +659,20 @@ var getMinMaxValue = function (value) {
|
|
|
647
659
|
}
|
|
648
660
|
};
|
|
649
661
|
exports.getMinMaxValue = getMinMaxValue;
|
|
650
|
-
var getValueOfProjectConstant = function (value, currentUser) {
|
|
662
|
+
var getValueOfProjectConstant = function (value, currentUser, timezone) {
|
|
663
|
+
if (!timezone)
|
|
664
|
+
timezone = "(GMT+5:30)";
|
|
665
|
+
timezone = timezone.substring(4, 10);
|
|
666
|
+
var result;
|
|
651
667
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
652
668
|
return currentUser["uuid"];
|
|
653
669
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
654
|
-
|
|
670
|
+
result = date_util_1.createLoggerDateFormat(timezone);
|
|
655
671
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
656
|
-
|
|
672
|
+
result = date_util_1.createLogsDateFormat(timezone);
|
|
657
673
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
658
|
-
|
|
674
|
+
result = date_util_1.getDateValue(value, timezone);
|
|
675
|
+
return result;
|
|
659
676
|
};
|
|
660
677
|
var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
661
678
|
var searchAggregateQuery = [];
|
|
@@ -35,12 +35,10 @@ 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
|
-
for (var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
r[k] = a[j];
|
|
43
|
-
return r;
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
39
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
40
|
+
to[j] = from[i];
|
|
41
|
+
return to;
|
|
44
42
|
};
|
|
45
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
44
|
exports.queryParserNew = void 0;
|
|
@@ -193,14 +191,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
193
191
|
}
|
|
194
192
|
}
|
|
195
193
|
});
|
|
196
|
-
console.log("==> aggregateQuery", aggregateQuery);
|
|
197
|
-
console.log("==> likeQuery", likeQuery_1);
|
|
198
194
|
if (likeQuery_1.length) {
|
|
199
195
|
// aggregateQuery.push({ $match: { $or: likeQuery } });
|
|
200
196
|
aggregateQuery.push({ $match: { $and: likeQuery_1 } });
|
|
201
197
|
}
|
|
202
198
|
}
|
|
203
|
-
console.log("==> query", query);
|
|
204
199
|
projection = mongoSelectQuery(query);
|
|
205
200
|
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy, aggregateFunctionField = query.aggregateFunctionField;
|
|
206
201
|
if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
|
|
@@ -331,7 +326,6 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
331
326
|
if (finder != "COUNT" && limit) {
|
|
332
327
|
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
333
328
|
}
|
|
334
|
-
console.log("==> aggregateQuery", JSON.stringify(aggregateQuery, null, 2));
|
|
335
329
|
queryStr = ".aggregate(" + JSON.stringify(aggregateQuery) + ", { collation: { locale: \"en\" } })";
|
|
336
330
|
str = "req.db.collection('" + collectionName + "')" + queryStr;
|
|
337
331
|
str += ".toArray()";
|
|
@@ -573,7 +567,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
573
567
|
endValue_1 = "" + externalParams[endValue_1];
|
|
574
568
|
}
|
|
575
569
|
else {
|
|
576
|
-
if (
|
|
570
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
577
571
|
return startValue_1.includes(cnst);
|
|
578
572
|
})) {
|
|
579
573
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
|
|
@@ -581,7 +575,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
581
575
|
else {
|
|
582
576
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
583
577
|
}
|
|
584
|
-
if (
|
|
578
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
585
579
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
|
|
586
580
|
}
|
|
587
581
|
else {
|
|
@@ -603,20 +597,16 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
603
597
|
else
|
|
604
598
|
return startValue_1 + "---" + endValue_1;
|
|
605
599
|
}
|
|
606
|
-
console.log("==> value", value);
|
|
607
|
-
console.log("==> currentUser", currentUser);
|
|
608
600
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
609
601
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
610
602
|
return currentUser["uuid"];
|
|
611
603
|
}
|
|
612
604
|
var splitValues = value.split("::");
|
|
613
|
-
console.log("splitValues", splitValues);
|
|
614
605
|
var refCollection = splitValues[1];
|
|
615
606
|
var refCollectionField = splitValues[2];
|
|
616
607
|
if (refCollection && refCollectionField) {
|
|
617
608
|
console.log("I have refCollection and Field");
|
|
618
609
|
var refCollectionData = currentUser[refCollection];
|
|
619
|
-
console.log("refCollectionData", refCollectionData);
|
|
620
610
|
if (!refCollectionData) {
|
|
621
611
|
return "";
|
|
622
612
|
}
|
package/build/utils/util.js
CHANGED
|
@@ -263,6 +263,8 @@ var replaceDataValueIntoExpression = function (expression, data, user, sessionVa
|
|
|
263
263
|
else {
|
|
264
264
|
if (Object.keys(data).length > 0) {
|
|
265
265
|
dataOfItem = exports.parseValueFromData(data, prop);
|
|
266
|
+
//TODO: Need better way
|
|
267
|
+
delete data[prop];
|
|
266
268
|
}
|
|
267
269
|
}
|
|
268
270
|
expression = replaceValueInExpression(needle, dataOfItem, expression);
|