@b2y/ecommerce-common 1.1.5 → 1.1.6
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/README.md +4 -4
- package/constants/AppConstants.js +6 -6
- package/constants/ReportConstants.js +14 -14
- package/constants/StatusMessageConstants.js +17 -17
- package/dbconnection/Connect.js +432 -432
- package/enum/AccessModeEnum.js +7 -7
- package/enum/AddressTypeEnum.js +6 -6
- package/enum/BillingCycleEnum.js +5 -5
- package/enum/BooleanEnum.js +4 -4
- package/enum/BulkImportStatusEnum.js +6 -6
- package/enum/EntityTypeEnum.js +11 -11
- package/enum/FeatureTypeEnum.js +6 -6
- package/enum/GenderEnum.js +7 -7
- package/enum/NotificationStatusEnum.js +5 -5
- package/enum/NotificationTypeEnum.js +9 -9
- package/enum/OrderStatusEnum.js +7 -7
- package/enum/PaymentMethodEnum.js +6 -6
- package/enum/PaymentStatusEnum.js +6 -6
- package/enum/PaymentTypeEnum.js +6 -6
- package/enum/PlatformEnum.js +4 -4
- package/enum/RegistrationStatusEnum.js +5 -5
- package/enum/SortByEnum.js +7 -7
- package/enum/SubscriptionStatusEnum.js +7 -7
- package/index.js +22 -22
- package/model/Address.js +95 -95
- package/model/AttributeType.js +50 -50
- package/model/AttributeValue.js +64 -64
- package/model/Banner.js +78 -78
- package/model/Brand.js +76 -76
- package/model/Cart.js +76 -76
- package/model/Category.js +72 -72
- package/model/CategoryAttributeType.js +62 -62
- package/model/Colour.js +52 -52
- package/model/Customer.js +94 -94
- package/model/DeviceToken.js +51 -51
- package/model/Document.js +73 -73
- package/model/DynamicUIComponent.js +52 -52
- package/model/Feedback.js +79 -79
- package/model/Inventory.js +87 -83
- package/model/NotificationHistory.js +67 -67
- package/model/Order.js +94 -94
- package/model/OrderItem.js +98 -98
- package/model/OrderItemHistory.js +69 -69
- package/model/OrderStatus.js +48 -48
- package/model/Payment.js +101 -101
- package/model/PaymentMethod.js +36 -36
- package/model/PaymentStatus.js +36 -36
- package/model/PaymentType.js +36 -36
- package/model/Permission.js +55 -55
- package/model/Product.js +87 -87
- package/model/ProductGroup.js +48 -48
- package/model/ProductImport.js +55 -55
- package/model/ProductImportFailureAudits.js +57 -57
- package/model/ProductSpecification.js +65 -65
- package/model/ProductVariant.js +75 -75
- package/model/ProductVariantAttribute.js +58 -58
- package/model/Role.js +61 -61
- package/model/RolePermissionMapping.js +63 -63
- package/model/SpecificationType.js +41 -41
- package/model/Store.js +99 -99
- package/model/StoreUserMapping.js +44 -44
- package/model/SubscriptionFeature.js +49 -49
- package/model/SubscriptionPlan.js +66 -66
- package/model/SubscriptionPlanFeature.js +48 -48
- package/model/Tenant.js +91 -91
- package/model/TenantSettings.js +47 -47
- package/model/TenantSubscription.js +73 -73
- package/model/User.js +132 -132
- package/model/WishList.js +62 -62
- package/package.json +29 -29
- package/utility/AppUtil.js +65 -65
- package/utility/DateUtil.js +55 -55
- package/utility/ExcelUtil.js +125 -125
- package/utility/LocationUtility.js +130 -130
- package/utility/OrderTimeFilterUtil.js +88 -88
- package/utility/PdfUtil.js +64 -64
- package/utility/QueryUtil.js +261 -261
- package/utility/Razorpay.js +65 -65
- package/utility/ResolveAccessMode.js +38 -38
- package/utility/VariantPriceUtil.js +54 -54
package/model/WishList.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
const { DataTypes } = require('sequelize');
|
|
2
|
-
|
|
3
|
-
module.exports = (sequelize) => {
|
|
4
|
-
return sequelize.define('WishList', {
|
|
5
|
-
WishListID: {
|
|
6
|
-
type: DataTypes.UUID,
|
|
7
|
-
primaryKey: true,
|
|
8
|
-
allowNull: false,
|
|
9
|
-
defaultValue: DataTypes.UUIDV4
|
|
10
|
-
},
|
|
11
|
-
TenantID: {
|
|
12
|
-
type: DataTypes.UUID,
|
|
13
|
-
allowNull: false,
|
|
14
|
-
references: {
|
|
15
|
-
model: 'Tenant',
|
|
16
|
-
key: 'TenantID'
|
|
17
|
-
},
|
|
18
|
-
onDelete: 'CASCADE',
|
|
19
|
-
onUpdate: 'CASCADE'
|
|
20
|
-
},
|
|
21
|
-
ProductVariantID: {
|
|
22
|
-
type: DataTypes.UUID,
|
|
23
|
-
allowNull: false,
|
|
24
|
-
references: {
|
|
25
|
-
model: 'ProductVariant',
|
|
26
|
-
key: 'ProductVariantID'
|
|
27
|
-
},
|
|
28
|
-
onDelete: 'RESTRICT',
|
|
29
|
-
onUpdate: 'CASCADE'
|
|
30
|
-
},
|
|
31
|
-
CustomerID: {
|
|
32
|
-
type: DataTypes.UUID,
|
|
33
|
-
allowNull: false,
|
|
34
|
-
references: {
|
|
35
|
-
model: 'Customer',
|
|
36
|
-
key: 'CustomerID'
|
|
37
|
-
},
|
|
38
|
-
onDelete: 'RESTRICT',
|
|
39
|
-
onUpdate: 'CASCADE'
|
|
40
|
-
},
|
|
41
|
-
CreatedBy: {
|
|
42
|
-
type: DataTypes.UUID,
|
|
43
|
-
allowNull: false
|
|
44
|
-
},
|
|
45
|
-
CreatedAt: {
|
|
46
|
-
type: DataTypes.DATE,
|
|
47
|
-
allowNull: false,
|
|
48
|
-
defaultValue: DataTypes.NOW
|
|
49
|
-
},
|
|
50
|
-
UpdatedBy: {
|
|
51
|
-
type: DataTypes.UUID,
|
|
52
|
-
allowNull: false
|
|
53
|
-
},
|
|
54
|
-
UpdatedAt: {
|
|
55
|
-
type: DataTypes.DATE,
|
|
56
|
-
allowNull: false,
|
|
57
|
-
defaultValue: DataTypes.NOW
|
|
58
|
-
}
|
|
59
|
-
}, {
|
|
60
|
-
tableName: 'WishList',
|
|
61
|
-
timestamps: false
|
|
62
|
-
});
|
|
1
|
+
const { DataTypes } = require('sequelize');
|
|
2
|
+
|
|
3
|
+
module.exports = (sequelize) => {
|
|
4
|
+
return sequelize.define('WishList', {
|
|
5
|
+
WishListID: {
|
|
6
|
+
type: DataTypes.UUID,
|
|
7
|
+
primaryKey: true,
|
|
8
|
+
allowNull: false,
|
|
9
|
+
defaultValue: DataTypes.UUIDV4
|
|
10
|
+
},
|
|
11
|
+
TenantID: {
|
|
12
|
+
type: DataTypes.UUID,
|
|
13
|
+
allowNull: false,
|
|
14
|
+
references: {
|
|
15
|
+
model: 'Tenant',
|
|
16
|
+
key: 'TenantID'
|
|
17
|
+
},
|
|
18
|
+
onDelete: 'CASCADE',
|
|
19
|
+
onUpdate: 'CASCADE'
|
|
20
|
+
},
|
|
21
|
+
ProductVariantID: {
|
|
22
|
+
type: DataTypes.UUID,
|
|
23
|
+
allowNull: false,
|
|
24
|
+
references: {
|
|
25
|
+
model: 'ProductVariant',
|
|
26
|
+
key: 'ProductVariantID'
|
|
27
|
+
},
|
|
28
|
+
onDelete: 'RESTRICT',
|
|
29
|
+
onUpdate: 'CASCADE'
|
|
30
|
+
},
|
|
31
|
+
CustomerID: {
|
|
32
|
+
type: DataTypes.UUID,
|
|
33
|
+
allowNull: false,
|
|
34
|
+
references: {
|
|
35
|
+
model: 'Customer',
|
|
36
|
+
key: 'CustomerID'
|
|
37
|
+
},
|
|
38
|
+
onDelete: 'RESTRICT',
|
|
39
|
+
onUpdate: 'CASCADE'
|
|
40
|
+
},
|
|
41
|
+
CreatedBy: {
|
|
42
|
+
type: DataTypes.UUID,
|
|
43
|
+
allowNull: false
|
|
44
|
+
},
|
|
45
|
+
CreatedAt: {
|
|
46
|
+
type: DataTypes.DATE,
|
|
47
|
+
allowNull: false,
|
|
48
|
+
defaultValue: DataTypes.NOW
|
|
49
|
+
},
|
|
50
|
+
UpdatedBy: {
|
|
51
|
+
type: DataTypes.UUID,
|
|
52
|
+
allowNull: false
|
|
53
|
+
},
|
|
54
|
+
UpdatedAt: {
|
|
55
|
+
type: DataTypes.DATE,
|
|
56
|
+
allowNull: false,
|
|
57
|
+
defaultValue: DataTypes.NOW
|
|
58
|
+
}
|
|
59
|
+
}, {
|
|
60
|
+
tableName: 'WishList',
|
|
61
|
+
timestamps: false
|
|
62
|
+
});
|
|
63
63
|
};
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@b2y/ecommerce-common",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "E-commerce common library",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/yuvakrishna29/ecommerce-common.git"
|
|
12
|
-
},
|
|
13
|
-
"publishConfig": {
|
|
14
|
-
"access": "public"
|
|
15
|
-
},
|
|
16
|
-
"author": "Shikha",
|
|
17
|
-
"license": "ISC",
|
|
18
|
-
"bugs": {
|
|
19
|
-
"url": "https://github.com/yuvakrishna29/ecommerce-common/issues"
|
|
20
|
-
},
|
|
21
|
-
"homepage": "https://github.com/yuvakrishna29/ecommerce-common#readme",
|
|
22
|
-
"peerDependencies": {
|
|
23
|
-
"@countrystatecity/countries": "^1.0.4",
|
|
24
|
-
"exceljs": "^4.4.0",
|
|
25
|
-
"luxon": "^3.7.2",
|
|
26
|
-
"puppeteer": "^24.35.0",
|
|
27
|
-
"sequelize": "^6.37.5"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@b2y/ecommerce-common",
|
|
3
|
+
"version": "1.1.6",
|
|
4
|
+
"description": "E-commerce common library",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/yuvakrishna29/ecommerce-common.git"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"author": "Shikha",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/yuvakrishna29/ecommerce-common/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/yuvakrishna29/ecommerce-common#readme",
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@countrystatecity/countries": "^1.0.4",
|
|
24
|
+
"exceljs": "^4.4.0",
|
|
25
|
+
"luxon": "^3.7.2",
|
|
26
|
+
"puppeteer": "^24.35.0",
|
|
27
|
+
"sequelize": "^6.37.5"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/utility/AppUtil.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
const BooleanEnum = require('../enum/BooleanEnum');
|
|
2
|
-
const AppUtil = {
|
|
3
|
-
generateResponse: function (statusCode, status, message, payload, res, customCode = null) {
|
|
4
|
-
let response = {
|
|
5
|
-
status,
|
|
6
|
-
};
|
|
7
|
-
if (
|
|
8
|
-
payload &&
|
|
9
|
-
(Array.isArray(payload) || Object.keys(payload).length > 0)
|
|
10
|
-
) {
|
|
11
|
-
if (payload.rows && typeof payload.count !== "undefined") {
|
|
12
|
-
const { rows, count, pageNumber, limit } = payload;
|
|
13
|
-
const currentPage = Number(pageNumber) || 1;
|
|
14
|
-
const pageSize = Number(limit) || count;
|
|
15
|
-
const totalPages = Math.ceil(count / pageSize);
|
|
16
|
-
response.data = rows;
|
|
17
|
-
response.pagination = {
|
|
18
|
-
totalRecords: count,
|
|
19
|
-
totalPages,
|
|
20
|
-
currentPage,
|
|
21
|
-
pageSize,
|
|
22
|
-
hasNext: currentPage < totalPages,
|
|
23
|
-
hasPrev: currentPage > 1,
|
|
24
|
-
};
|
|
25
|
-
} else {
|
|
26
|
-
// Non-paginated response
|
|
27
|
-
response.data = payload;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (message) {
|
|
31
|
-
// No data => return message (POST/PUT/DELETE-like APIs)
|
|
32
|
-
response.message = message || "";
|
|
33
|
-
}
|
|
34
|
-
// if custome code also need to send in reponse body
|
|
35
|
-
if (customCode) {
|
|
36
|
-
response.customCode = customCode;
|
|
37
|
-
}
|
|
38
|
-
res.status(statusCode).send(response);
|
|
39
|
-
},
|
|
40
|
-
parseIsActive: function (isActive) {
|
|
41
|
-
if (isActive === true || isActive === "true") return BooleanEnum.TRUE;
|
|
42
|
-
if (isActive === false || isActive === "false") return BooleanEnum.FALSE;
|
|
43
|
-
return undefined;
|
|
44
|
-
},
|
|
45
|
-
getPagination: function (page, size) {
|
|
46
|
-
if (!size || !page) return {};
|
|
47
|
-
const limit = +size;
|
|
48
|
-
const offset = (page - 1) * limit;
|
|
49
|
-
return { limit, offset };
|
|
50
|
-
},
|
|
51
|
-
trimDecimal: function (decimal) {
|
|
52
|
-
const value = parseFloat(decimal);
|
|
53
|
-
return Math.round(value)
|
|
54
|
-
},
|
|
55
|
-
isValidEmail: function (email) {
|
|
56
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
57
|
-
return emailRegex.test(email.trim());
|
|
58
|
-
},
|
|
59
|
-
isValidPhone: function (phoneNumber) {
|
|
60
|
-
const phoneRegex = /^\d{10,20}$/;
|
|
61
|
-
return phoneRegex.test(phoneNumber);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
|
|
1
|
+
const BooleanEnum = require('../enum/BooleanEnum');
|
|
2
|
+
const AppUtil = {
|
|
3
|
+
generateResponse: function (statusCode, status, message, payload, res, customCode = null) {
|
|
4
|
+
let response = {
|
|
5
|
+
status,
|
|
6
|
+
};
|
|
7
|
+
if (
|
|
8
|
+
payload &&
|
|
9
|
+
(Array.isArray(payload) || Object.keys(payload).length > 0)
|
|
10
|
+
) {
|
|
11
|
+
if (payload.rows && typeof payload.count !== "undefined") {
|
|
12
|
+
const { rows, count, pageNumber, limit } = payload;
|
|
13
|
+
const currentPage = Number(pageNumber) || 1;
|
|
14
|
+
const pageSize = Number(limit) || count;
|
|
15
|
+
const totalPages = Math.ceil(count / pageSize);
|
|
16
|
+
response.data = rows;
|
|
17
|
+
response.pagination = {
|
|
18
|
+
totalRecords: count,
|
|
19
|
+
totalPages,
|
|
20
|
+
currentPage,
|
|
21
|
+
pageSize,
|
|
22
|
+
hasNext: currentPage < totalPages,
|
|
23
|
+
hasPrev: currentPage > 1,
|
|
24
|
+
};
|
|
25
|
+
} else {
|
|
26
|
+
// Non-paginated response
|
|
27
|
+
response.data = payload;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (message) {
|
|
31
|
+
// No data => return message (POST/PUT/DELETE-like APIs)
|
|
32
|
+
response.message = message || "";
|
|
33
|
+
}
|
|
34
|
+
// if custome code also need to send in reponse body
|
|
35
|
+
if (customCode) {
|
|
36
|
+
response.customCode = customCode;
|
|
37
|
+
}
|
|
38
|
+
res.status(statusCode).send(response);
|
|
39
|
+
},
|
|
40
|
+
parseIsActive: function (isActive) {
|
|
41
|
+
if (isActive === true || isActive === "true") return BooleanEnum.TRUE;
|
|
42
|
+
if (isActive === false || isActive === "false") return BooleanEnum.FALSE;
|
|
43
|
+
return undefined;
|
|
44
|
+
},
|
|
45
|
+
getPagination: function (page, size) {
|
|
46
|
+
if (!size || !page) return {};
|
|
47
|
+
const limit = +size;
|
|
48
|
+
const offset = (page - 1) * limit;
|
|
49
|
+
return { limit, offset };
|
|
50
|
+
},
|
|
51
|
+
trimDecimal: function (decimal) {
|
|
52
|
+
const value = parseFloat(decimal);
|
|
53
|
+
return Math.round(value)
|
|
54
|
+
},
|
|
55
|
+
isValidEmail: function (email) {
|
|
56
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
57
|
+
return emailRegex.test(email.trim());
|
|
58
|
+
},
|
|
59
|
+
isValidPhone: function (phoneNumber) {
|
|
60
|
+
const phoneRegex = /^\d{10,20}$/;
|
|
61
|
+
return phoneRegex.test(phoneNumber);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
|
|
66
66
|
module.exports = AppUtil;
|
package/utility/DateUtil.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
const AppConstants = require('../constants/AppConstants');
|
|
2
|
-
const {DateTime} = require('luxon');
|
|
3
|
-
const StatusMessage = require('../constants/StatusMessageConstants');
|
|
4
|
-
const DateUtil = {
|
|
5
|
-
isValidDate: function (dateStr) {
|
|
6
|
-
const dt = DateTime.fromISO(dateStr);
|
|
7
|
-
return dt.isValid;
|
|
8
|
-
},
|
|
9
|
-
getDateRange: function (startDate, endDate, logger) {
|
|
10
|
-
let currentStartDate, currentEndDate, previousStartDate, previousEndDate;
|
|
11
|
-
if (startDate && endDate) {
|
|
12
|
-
if (!this.isValidDate(startDate) || !this.isValidDate(endDate)) {
|
|
13
|
-
logger.warn("invalid date format");
|
|
14
|
-
throw new Error(StatusMessage.INVALID_DATE_FORMAT);
|
|
15
|
-
}
|
|
16
|
-
currentStartDate = DateTime.fromISO(startDate, { zone: "utc" });
|
|
17
|
-
currentEndDate = DateTime.fromISO(endDate, { zone: "utc" });
|
|
18
|
-
if (currentStartDate > currentEndDate) {
|
|
19
|
-
logger.warn("invalid date range");
|
|
20
|
-
throw new Error(StatusMessage.INVALID_DATE_RANGE);
|
|
21
|
-
}
|
|
22
|
-
const duration = currentEndDate.diff(currentStartDate);
|
|
23
|
-
previousEndDate = currentStartDate;
|
|
24
|
-
previousStartDate = previousEndDate.minus(duration);
|
|
25
|
-
} else if (startDate || endDate) {
|
|
26
|
-
// Only one provided
|
|
27
|
-
logger.warn("start date and date date both required");
|
|
28
|
-
throw new Error(StatusMessage.DATE_RANGE_REQUIRED);
|
|
29
|
-
} else {
|
|
30
|
-
// Default 7 days including today
|
|
31
|
-
currentEndDate = DateTime.utc();
|
|
32
|
-
currentStartDate = currentEndDate.minus({
|
|
33
|
-
days: AppConstants.DASHBOARD_DEFAULT_DAYS - 1,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const duration = currentEndDate.diff(currentStartDate);
|
|
37
|
-
previousEndDate = currentStartDate;
|
|
38
|
-
previousStartDate = previousEndDate.minus(duration);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
currentStartDate: currentStartDate.toISO(),
|
|
43
|
-
currentEndDate: currentEndDate.toISO(),
|
|
44
|
-
previousStartDate: previousStartDate.toISO(),
|
|
45
|
-
previousEndDate: previousEndDate.toISO(),
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
formatDate: function (date) {
|
|
49
|
-
if (!(date instanceof Date)) return null;
|
|
50
|
-
// conver JS date object to luxon date time
|
|
51
|
-
const dt = DateTime.fromJSDate(date);
|
|
52
|
-
return dt.toFormat('dd/MM/yyyy HH:mm:ss');
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
module.exports = DateUtil;
|
|
1
|
+
const AppConstants = require('../constants/AppConstants');
|
|
2
|
+
const {DateTime} = require('luxon');
|
|
3
|
+
const StatusMessage = require('../constants/StatusMessageConstants');
|
|
4
|
+
const DateUtil = {
|
|
5
|
+
isValidDate: function (dateStr) {
|
|
6
|
+
const dt = DateTime.fromISO(dateStr);
|
|
7
|
+
return dt.isValid;
|
|
8
|
+
},
|
|
9
|
+
getDateRange: function (startDate, endDate, logger) {
|
|
10
|
+
let currentStartDate, currentEndDate, previousStartDate, previousEndDate;
|
|
11
|
+
if (startDate && endDate) {
|
|
12
|
+
if (!this.isValidDate(startDate) || !this.isValidDate(endDate)) {
|
|
13
|
+
logger.warn("invalid date format");
|
|
14
|
+
throw new Error(StatusMessage.INVALID_DATE_FORMAT);
|
|
15
|
+
}
|
|
16
|
+
currentStartDate = DateTime.fromISO(startDate, { zone: "utc" });
|
|
17
|
+
currentEndDate = DateTime.fromISO(endDate, { zone: "utc" });
|
|
18
|
+
if (currentStartDate > currentEndDate) {
|
|
19
|
+
logger.warn("invalid date range");
|
|
20
|
+
throw new Error(StatusMessage.INVALID_DATE_RANGE);
|
|
21
|
+
}
|
|
22
|
+
const duration = currentEndDate.diff(currentStartDate);
|
|
23
|
+
previousEndDate = currentStartDate;
|
|
24
|
+
previousStartDate = previousEndDate.minus(duration);
|
|
25
|
+
} else if (startDate || endDate) {
|
|
26
|
+
// Only one provided
|
|
27
|
+
logger.warn("start date and date date both required");
|
|
28
|
+
throw new Error(StatusMessage.DATE_RANGE_REQUIRED);
|
|
29
|
+
} else {
|
|
30
|
+
// Default 7 days including today
|
|
31
|
+
currentEndDate = DateTime.utc();
|
|
32
|
+
currentStartDate = currentEndDate.minus({
|
|
33
|
+
days: AppConstants.DASHBOARD_DEFAULT_DAYS - 1,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const duration = currentEndDate.diff(currentStartDate);
|
|
37
|
+
previousEndDate = currentStartDate;
|
|
38
|
+
previousStartDate = previousEndDate.minus(duration);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
currentStartDate: currentStartDate.toISO(),
|
|
43
|
+
currentEndDate: currentEndDate.toISO(),
|
|
44
|
+
previousStartDate: previousStartDate.toISO(),
|
|
45
|
+
previousEndDate: previousEndDate.toISO(),
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
formatDate: function (date) {
|
|
49
|
+
if (!(date instanceof Date)) return null;
|
|
50
|
+
// conver JS date object to luxon date time
|
|
51
|
+
const dt = DateTime.fromJSDate(date);
|
|
52
|
+
return dt.toFormat('dd/MM/yyyy HH:mm:ss');
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
module.exports = DateUtil;
|