@b2y/ecommerce-common 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +4 -4
  2. package/constants/AppConstants.js +14 -6
  3. package/constants/ReportConstants.js +14 -14
  4. package/constants/StatusMessageConstants.js +54 -17
  5. package/controller/LocationController.js +144 -0
  6. package/controller/SubscriptionAbstractController.js +161 -0
  7. package/controller/TenantAbstractController.js +349 -0
  8. package/controller/TenantSettingsAbstractController.js +70 -0
  9. package/dbconnection/Connect.js +432 -432
  10. package/enum/AccessModeEnum.js +7 -7
  11. package/enum/AddressTypeEnum.js +6 -6
  12. package/enum/BillingCycleEnum.js +5 -5
  13. package/enum/BooleanEnum.js +4 -4
  14. package/enum/BulkImportStatusEnum.js +6 -6
  15. package/enum/EntityTypeEnum.js +11 -11
  16. package/enum/FeatureTypeEnum.js +6 -6
  17. package/enum/GenderEnum.js +7 -7
  18. package/enum/NotificationStatusEnum.js +5 -5
  19. package/enum/NotificationTypeEnum.js +9 -9
  20. package/enum/OrderStatusEnum.js +7 -7
  21. package/enum/PaymentMethodEnum.js +6 -6
  22. package/enum/PaymentStatusEnum.js +6 -6
  23. package/enum/PaymentTypeEnum.js +6 -6
  24. package/enum/PlatformEnum.js +4 -4
  25. package/enum/RegistrationStatusEnum.js +5 -5
  26. package/enum/SortByEnum.js +7 -7
  27. package/enum/SubscriptionStatusEnum.js +7 -7
  28. package/index.js +25 -22
  29. package/model/Address.js +95 -95
  30. package/model/AttributeType.js +50 -50
  31. package/model/AttributeValue.js +64 -64
  32. package/model/Banner.js +78 -78
  33. package/model/Brand.js +76 -76
  34. package/model/Cart.js +76 -76
  35. package/model/Category.js +72 -72
  36. package/model/CategoryAttributeType.js +62 -62
  37. package/model/Colour.js +52 -52
  38. package/model/Customer.js +94 -94
  39. package/model/DeviceToken.js +51 -51
  40. package/model/Document.js +73 -73
  41. package/model/DynamicUIComponent.js +52 -52
  42. package/model/Feedback.js +79 -79
  43. package/model/Inventory.js +87 -83
  44. package/model/NotificationHistory.js +67 -67
  45. package/model/Order.js +94 -94
  46. package/model/OrderItem.js +98 -98
  47. package/model/OrderItemHistory.js +69 -69
  48. package/model/OrderStatus.js +48 -48
  49. package/model/Payment.js +101 -101
  50. package/model/PaymentMethod.js +36 -36
  51. package/model/PaymentStatus.js +36 -36
  52. package/model/PaymentType.js +36 -36
  53. package/model/Permission.js +55 -55
  54. package/model/Product.js +87 -87
  55. package/model/ProductGroup.js +48 -48
  56. package/model/ProductImport.js +55 -55
  57. package/model/ProductImportFailureAudits.js +57 -57
  58. package/model/ProductSpecification.js +65 -65
  59. package/model/ProductVariant.js +75 -75
  60. package/model/ProductVariantAttribute.js +58 -58
  61. package/model/Role.js +61 -61
  62. package/model/RolePermissionMapping.js +63 -63
  63. package/model/SpecificationType.js +41 -41
  64. package/model/Store.js +99 -99
  65. package/model/StoreUserMapping.js +44 -44
  66. package/model/SubscriptionFeature.js +49 -49
  67. package/model/SubscriptionPlan.js +66 -66
  68. package/model/SubscriptionPlanFeature.js +48 -48
  69. package/model/Tenant.js +91 -91
  70. package/model/TenantSettings.js +47 -47
  71. package/model/TenantSubscription.js +73 -73
  72. package/model/User.js +132 -132
  73. package/model/WishList.js +62 -62
  74. package/package.json +29 -29
  75. package/utility/AppUtil.js +65 -65
  76. package/utility/DateUtil.js +55 -55
  77. package/utility/ExcelUtil.js +125 -125
  78. package/utility/LocationUtility.js +130 -130
  79. package/utility/OrderTimeFilterUtil.js +88 -88
  80. package/utility/PdfUtil.js +64 -64
  81. package/utility/QueryUtil.js +261 -261
  82. package/utility/Razorpay.js +65 -65
  83. package/utility/ResolveAccessMode.js +38 -38
  84. package/utility/VariantPriceUtil.js +54 -54
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ecommerce-common
2
- E-commerce common library
3
- A reusable, modular **common package** containing shared models, utilities, enums, helpers, and base configurations for the E-Commerce platform.
4
- This package centralizes ecommerce-Admin and ecommerce-customer cross-project logic so multiple services can stay consistent and maintainable.
1
+ # ecommerce-common
2
+ E-commerce common library
3
+ A reusable, modular **common package** containing shared models, utilities, enums, helpers, and base configurations for the E-Commerce platform.
4
+ This package centralizes ecommerce-Admin and ecommerce-customer cross-project logic so multiple services can stay consistent and maintainable.
@@ -1,7 +1,15 @@
1
- const AppConstants = {
2
- DASHBOARD_DEFAULT_DAYS : 7,
3
- LAST_30DAYS: 'LAST30DAYS',
4
- LAST_6MONTHS: 'LAST6MONTHS',
5
- OLDER: 'OLDER',
6
- }
1
+ const AppConstants = {
2
+ DASHBOARD_DEFAULT_DAYS : 7,
3
+ LAST_30DAYS: 'LAST30DAYS',
4
+ LAST_6MONTHS: 'LAST6MONTHS',
5
+ OLDER: 'OLDER',
6
+ COMPANY_NAME: 'CompanyName',
7
+ COMPANY_CODE: 'CompanyCode',
8
+ EMAIL: 'Email',
9
+ PHONE_NUMBER: 'PhoneNumber',
10
+ CUSTOMER_PORTAL_DOMAIN: 'CustomerPortalDomain',
11
+ ADMIN_PORTAL_DOMAIN: 'AdminPortalDomain',
12
+ CREATED_BY:'0000d6ab-8064-4786-a906-f458567224b8',
13
+ BOOLEAN:'boolean'
14
+ }
7
15
  module.exports = AppConstants;
@@ -1,15 +1,15 @@
1
-
2
- const EXCEL_METADATA = {
3
- CREATOR: "Ecommerce System", // this can be customized as per requirement
4
- LAST_MODIFIED_BY: "Ecommerce System"
5
- };
6
-
7
- const EXCEL_DEFAULT_THEME = {
8
- HEADER_FILL_COLOR: "1E90FF", // default header color
9
- HEADER_FONT_COLOR: "FFFFFFFF"
10
- };
11
-
12
- module.exports = {
13
- EXCEL_METADATA,
14
- EXCEL_DEFAULT_THEME
1
+
2
+ const EXCEL_METADATA = {
3
+ CREATOR: "Ecommerce System", // this can be customized as per requirement
4
+ LAST_MODIFIED_BY: "Ecommerce System"
5
+ };
6
+
7
+ const EXCEL_DEFAULT_THEME = {
8
+ HEADER_FILL_COLOR: "1E90FF", // default header color
9
+ HEADER_FONT_COLOR: "FFFFFFFF"
10
+ };
11
+
12
+ module.exports = {
13
+ EXCEL_METADATA,
14
+ EXCEL_DEFAULT_THEME
15
15
  };
@@ -1,18 +1,55 @@
1
- const StatusMessageConstants = {
2
- PRODUCTVARIANT_INVALID_MRP: 'Invalid MRP: must be positive',
3
- PRODUCTVARIANT_MISSING_PRICE_OR_DISCOUNT: 'Either SellingPrice or DiscountPercentage must be provided',
4
- PRODUCTVARIANT_INCONSISTENT_PRICING: 'Inconsistent pricing: provided discount percentage does not match calculated value',
5
- PRODUCTVARIANT_SELLING_PRICE_EXCEEDS_MRP: 'SellingPrice cannot exceed MRP',
6
- PRODUCTVARIANT_INVALID_SELLING_PRICE: 'SellingPrice cannot be negative',
7
- PRODUCTVARIANT_INVALID_DISCOUNT_PERCENTAGE: 'DiscountPercentage must be between 0 and 100',
8
- INVALID_DATE_FORMAT: "Invalid date format",
9
- INVALID_DATE_RANGE: "StartDate cannot be after EndDate",
10
- DATE_RANGE_REQUIRED: "Both startDate and endDate must be provided together",
11
- INVALID_END_DATE: "Invalid endDate",
12
- INVALID_START_DATE: "Invalid startDate",
13
- INVALID_ISACTIVE_STATUS: "IsActive must be either true or false",
14
- ORDER_CREATION_FAILED:"Order creation failed",
15
- PAYMENT_SIGNATURE_VERIFICATION_FAILED:"Payment signature verification failed",
16
- PAYMENT_VERIFICATION_FAILED:"Payment verification failed"
17
- }
1
+ const StatusMessageConstants = {
2
+ SUCCESS: 'Success',
3
+ FAILURE: 'Failure',
4
+ INVALID_REQUEST: 'Invalid request parameters',
5
+ SERVER_ERROR: 'Internal server error',
6
+ // Tenant
7
+ TENANT_NOT_FOUND: 'Tenant not found',
8
+ TENANT_ID_REQUIRED_FIELD: 'TenantID is required for updating the tenant',
9
+ TENANT_UPDATED_SUCCESS: 'Tenant updated successfully',
10
+ TENANT_UPDATE_ERROR: 'Failed to update tenant',
11
+ TENANT_ALREADY_EXISTS: 'Tenant with this information already exists',
12
+ INVALID_EMAIL_FORMAT: 'Invalid email format provided',
13
+ INVALID_PHONE_FORMAT: 'Phone number must be 10-20 digits',
14
+ INVALID_COMPANY_CODE: 'Company code must be a valid positive integer',
15
+ INVALID_SUBSCRIPTION_STATUS: "Invalid subscription status",
16
+ COMPANY_NAME_EXISTS: 'Company name already exists',
17
+ COMPANY_CODE_EXISTS: 'Company code already exists',
18
+ EMAIL_EXISTS: 'Email already exists',
19
+ PHONE_NUMBER_EXISTS: 'Phone number already exists',
20
+ CUSTOMER_PORTAL_DOMAIN_EXISTS: 'Customer portal domain already exists',
21
+ ADMIN_PORTAL_DOMAIN_EXISTS: 'Admin portal domain already exists',
22
+ INVALID_START_END_DATE: 'End date can not be before start date',
23
+ SUBSCRIPTION_PLAN_NOT_FOUND: "Subscription plan not found",
24
+ INVALID_BOOLEAN_TYPE: "{field} must be boolean value",
25
+
26
+ //TenantSettings
27
+ TENANT_SETTINGS_NOT_FOUND: "Tenant settings not foundd",
28
+
29
+ //Location
30
+ STATE_CODE_COUNTRY_CODE_REQUIRE: "State code and country code are required to fetch cities",
31
+ CITIES_NOT_FOUND: "No cities found for given state code",
32
+ COUNTRY_CODE_REQUIRE: "Country code is required to fetch states",
33
+ STATES_NOT_FOUND: "No states found for given country code",
34
+ STATES_FETCH_ERROR: "Error occured while fetching states",
35
+ CITIES_FETCH_ERROR: "Error occurred while fetching cities",
36
+ COUNTRIES_FETCH_ERROR: "Error occurred while fetching countries",
37
+
38
+ // Product Variant
39
+ PRODUCTVARIANT_INVALID_MRP: 'Invalid MRP: must be positive',
40
+ PRODUCTVARIANT_MISSING_PRICE_OR_DISCOUNT: 'Either SellingPrice or DiscountPercentage must be provided',
41
+ PRODUCTVARIANT_INCONSISTENT_PRICING: 'Inconsistent pricing: provided discount percentage does not match calculated value',
42
+ PRODUCTVARIANT_SELLING_PRICE_EXCEEDS_MRP: 'SellingPrice cannot exceed MRP',
43
+ PRODUCTVARIANT_INVALID_SELLING_PRICE: 'SellingPrice cannot be negative',
44
+ PRODUCTVARIANT_INVALID_DISCOUNT_PERCENTAGE: 'DiscountPercentage must be between 0 and 100',
45
+ INVALID_DATE_FORMAT: "Invalid date format",
46
+ INVALID_DATE_RANGE: "StartDate cannot be after EndDate",
47
+ DATE_RANGE_REQUIRED: "Both startDate and endDate must be provided together",
48
+ INVALID_END_DATE: "Invalid endDate",
49
+ INVALID_START_DATE: "Invalid startDate",
50
+ INVALID_ISACTIVE_STATUS: "IsActive must be either true or false",
51
+ ORDER_CREATION_FAILED:"Order creation failed",
52
+ PAYMENT_SIGNATURE_VERIFICATION_FAILED:"Payment signature verification failed",
53
+ PAYMENT_VERIFICATION_FAILED:"Payment verification failed"
54
+ }
18
55
  module.exports = StatusMessageConstants;
@@ -0,0 +1,144 @@
1
+ const {
2
+ getCountries,
3
+ getStatesOfCountry,
4
+ getCitiesOfState,
5
+ } = require("@countrystatecity/countries");
6
+ const AppUtil = require("../utility/AppUtil");
7
+ const StatusMessage = require("../constants/StatusMessageConstants");
8
+
9
+ // Get all cities by state filters
10
+ const getCitiesByState = (logger) => {
11
+ return async (req, res) => {
12
+ try {
13
+ const { countryCode, stateCode } = req.params;
14
+ if (!countryCode || !stateCode) {
15
+ return AppUtil.generateResponse(
16
+ 400,
17
+ StatusMessage.FAILURE,
18
+ StatusMessage.STATE_CODE_COUNTRY_CODE_REQUIRE,
19
+ null,
20
+ res,
21
+ );
22
+ }
23
+ const cities = await getCitiesOfState(countryCode, stateCode);
24
+ if (!cities || cities.length === 0) {
25
+ logger.debug("No cities found for state code:", stateCode);
26
+ return AppUtil.generateResponse(
27
+ 200,
28
+ StatusMessage.SUCCESS,
29
+ StatusMessage.CITIES_NOT_FOUND,
30
+ null,
31
+ res,
32
+ );
33
+ }
34
+ const cityNames = cities.map((c) => ({
35
+ CityName: c.name,
36
+ latitude: c.latitude,
37
+ longitude: c.longitude,
38
+ }));
39
+ logger.debug("cities retrieved successfully");
40
+ return AppUtil.generateResponse(
41
+ 200,
42
+ StatusMessage.SUCCESS,
43
+ null,
44
+ cityNames,
45
+ res,
46
+ );
47
+ } catch (error) {
48
+ logger.error("Invalid filter format:", error);
49
+ return AppUtil.generateResponse(
50
+ 500,
51
+ StatusMessage.FAILURE,
52
+ StatusMessage.CITIES_FETCH_ERROR,
53
+ null,
54
+ res,
55
+ );
56
+ }
57
+ };
58
+ }
59
+
60
+ const getStatesByCountry = (logger) => {
61
+ return async (req, res) => {
62
+ try {
63
+ const { countryCode } = req.params;
64
+ if (!countryCode) {
65
+ return AppUtil.generateResponse(
66
+ 400,
67
+ StatusMessage.FAILURE,
68
+ StatusMessage.COUNTRY_CODE_REQUIRE,
69
+ null,
70
+ res,
71
+ );
72
+ }
73
+ const states = await getStatesOfCountry(countryCode);
74
+ if (!states || states.length === 0) {
75
+ logger.debug("No states found for country code:", countryCode);
76
+ return AppUtil.generateResponse(
77
+ 200,
78
+ StatusMessage.SUCCESS,
79
+ StatusMessage.STATES_NOT_FOUND,
80
+ null,
81
+ res,
82
+ );
83
+ }
84
+ // Transform to simpler format
85
+ const formattedStates = states.map((s) => ({
86
+ Code: s.iso2,
87
+ StateName: s.name,
88
+ StateCode: s.state_code,
89
+ }));
90
+ logger.debug("States retrieved successfully");
91
+ return AppUtil.generateResponse(
92
+ 200,
93
+ StatusMessage.SUCCESS,
94
+ null,
95
+ formattedStates,
96
+ res,
97
+ );
98
+ } catch (error) {
99
+ logger.error("Error searching for country:", error);
100
+ return AppUtil.generateResponse(
101
+ 500,
102
+ StatusMessage.FAILURE,
103
+ StatusMessage.STATES_FETCH_ERROR,
104
+ null,
105
+ res,
106
+ );
107
+ }
108
+ };
109
+ }
110
+
111
+ //Getall countries list
112
+ const getAllCountries = (logger) => {
113
+ return async (req, res) => {
114
+ try {
115
+ const countries = await getCountries();
116
+ // transform to simpler format
117
+ const formattedCountries = countries.map((country) => ({
118
+ CountryCode: country.iso2,
119
+ CountryName: country.name,
120
+ iso3: country.iso3,
121
+ PhoneCode: country.phonecode,
122
+ flag: country.emoji,
123
+ }));
124
+ return AppUtil.generateResponse(
125
+ 200,
126
+ StatusMessage.SUCCESS,
127
+ null,
128
+ formattedCountries,
129
+ res,
130
+ );
131
+ } catch (error) {
132
+ logger.error("Error fetching countries:", error);
133
+ return AppUtil.generateResponse(
134
+ 500,
135
+ StatusMessage.FAILURE,
136
+ StatusMessage.COUNTRIES_FETCH_ERROR,
137
+ null,
138
+ res,
139
+ );
140
+ }
141
+ };
142
+ }
143
+
144
+ module.exports = { getCitiesByState, getStatesByCountry, getAllCountries };
@@ -0,0 +1,161 @@
1
+ const StatusMessage = require('../constants/StatusMessageConstants');
2
+ const AppUtil = require('../utility/AppUtil');
3
+ const LocationUtility = require('../utility/LocationUtility');
4
+
5
+ // getAllSubscriptionPlans
6
+ const getAllSubscriptionPlans = (
7
+ SubscriptionPlan,
8
+ SubscriptionFeature,
9
+ logger,
10
+ ) => {
11
+ return async (req, res) => {
12
+ const { pageNumber, pageSize } = req.query;
13
+ const { limit, offset } = AppUtil.getPagination(pageNumber, pageSize);
14
+ try {
15
+ const { rows, count } = await SubscriptionPlan.findAndCountAll({
16
+ attributes: [
17
+ "SubscriptionPlanID",
18
+ "PlanName",
19
+ "PlanCode",
20
+ "Price",
21
+ "BillingCycle",
22
+ "Currency",
23
+ "TrialPeriodDays",
24
+ "IsActive",
25
+ ],
26
+ include: [
27
+ {
28
+ model: SubscriptionFeature,
29
+ as: "Features",
30
+ attributes: ["SubscriptionFeatureID", "FeatureName", "FeatureCode"],
31
+ through: { attributes: ["FeatureValue"] },
32
+ },
33
+ ],
34
+ limit,
35
+ offset,
36
+ distinct: true,
37
+ });
38
+ logger.debug("subscription plans fetched successfully");
39
+ return AppUtil.generateResponse(
40
+ 200,
41
+ StatusMessage.SUCCESS,
42
+ null,
43
+ { rows, count, pageNumber, limit },
44
+ res,
45
+ );
46
+ } catch (error) {
47
+ logger.error("error occurred while fetching subscription plans", error);
48
+ return AppUtil.generateResponse(
49
+ 500,
50
+ StatusMessage.FAILURE,
51
+ StatusMessage.SERVER_ERROR,
52
+ null,
53
+ res,
54
+ );
55
+ }
56
+ };
57
+ };
58
+
59
+ const getTenantSubscription = (
60
+ Tenant,
61
+ TenantSubscription,
62
+ SubscriptionPlan,
63
+ logger,
64
+ ) => {
65
+ return async (req, res) => {
66
+ try {
67
+ const { id } = req.params;
68
+
69
+ const tenant = await Tenant.findOne({
70
+ where: { TenantID: id },
71
+ include: [
72
+ {
73
+ model: TenantSubscription,
74
+ as: "CurrentSubscription",
75
+ attributes: [
76
+ "TenantSubscriptionID",
77
+ "Status",
78
+ "StartDate",
79
+ "EndDate",
80
+ "GraceEndDate",
81
+ "TrialEndDate",
82
+ "IsTrial",
83
+ "AutoRenew",
84
+ ],
85
+ include: [
86
+ {
87
+ model: SubscriptionPlan,
88
+ as: "SubscriptionPlan",
89
+ attributes: ["SubscriptionPlanID", "PlanName", "PlanCode"],
90
+ },
91
+ ],
92
+ },
93
+ ],
94
+ });
95
+
96
+ if (!tenant) {
97
+ return AppUtil.generateResponse(
98
+ 404,
99
+ StatusMessage.FAILURE,
100
+ StatusMessage.TENANT_NOT_FOUND,
101
+ null,
102
+ res,
103
+ );
104
+ }
105
+
106
+ const { countryName, stateName } =
107
+ await LocationUtility.resolveCountryAndState(
108
+ tenant.CountryCode,
109
+ tenant.StateCode,
110
+ logger,
111
+ );
112
+
113
+ const formattedTenant = {
114
+ TenantID: tenant.TenantID,
115
+ CompanyName: tenant.CompanyName,
116
+ CompanyCode: tenant.CompanyCode,
117
+ Email: tenant.Email,
118
+ CountryCallingCode: tenant.CountryCallingCode,
119
+ PhoneNumber: tenant.PhoneNumber,
120
+ GSTNo: tenant.GSTNo,
121
+ CustomerPortalDomain: tenant.CustomerPortalDomain,
122
+ AdminPortalDomain: tenant.AdminPortalDomain,
123
+ AddressLine: tenant.AddressLine,
124
+ CityName: tenant.CityName,
125
+ StateCode: tenant.StateCode,
126
+ StateName: stateName,
127
+ CountryCode: tenant.CountryCode,
128
+ CountryName: countryName,
129
+ Zipcode: tenant.Zipcode,
130
+ SubscriptionPlanID: tenant.CurrentSubscription?.SubscriptionPlan?.SubscriptionPlanID,
131
+ PlanName: tenant.CurrentSubscription?.SubscriptionPlan?.PlanName,
132
+ TenantSubscriptionStatus: tenant.CurrentSubscription?.Status,
133
+ StartDate: tenant.CurrentSubscription?.StartDate,
134
+ EndDate: tenant.CurrentSubscription?.EndDate,
135
+ GraceEndDate: tenant.CurrentSubscription?.GraceEndDate,
136
+ TrialEndDate: tenant.CurrentSubscription?.TrialEndDate,
137
+ IsTrial: tenant.CurrentSubscription?.IsTrial,
138
+ AutoRenew: tenant.CurrentSubscription?.AutoRenew,
139
+ };
140
+
141
+ return AppUtil.generateResponse(
142
+ 200,
143
+ StatusMessage.SUCCESS,
144
+ null,
145
+ formattedTenant,
146
+ res,
147
+ );
148
+ } catch (error) {
149
+ logger.error("Error fetching tenant:", error);
150
+ return AppUtil.generateResponse(
151
+ 500,
152
+ StatusMessage.FAILURE,
153
+ StatusMessage.SERVER_ERROR,
154
+ null,
155
+ res,
156
+ );
157
+ }
158
+ };
159
+ };
160
+
161
+ module.exports = {getAllSubscriptionPlans, getTenantSubscription}