@b2y/ecommerce-common 1.3.5 → 1.3.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 (96) hide show
  1. package/.idea/ecommerce-common.iml +11 -11
  2. package/.idea/modules.xml +7 -7
  3. package/.idea/vcs.xml +5 -5
  4. package/README.md +4 -4
  5. package/constants/AppConstants.js +15 -15
  6. package/constants/ReportConstants.js +14 -14
  7. package/constants/StatusMessageConstants.js +61 -61
  8. package/controller/LocationController.js +144 -144
  9. package/controller/SubscriptionAbstractController.js +91 -91
  10. package/controller/TenantAbstractController.js +152 -152
  11. package/controller/TenantSettingsAbstractController.js +243 -243
  12. package/dbconnection/Connect.js +498 -498
  13. package/enum/AccessModeEnum.js +8 -8
  14. package/enum/ActionByTypeEnum.js +4 -4
  15. package/enum/AddressTypeEnum.js +6 -6
  16. package/enum/BillingCycleEnum.js +5 -5
  17. package/enum/BooleanEnum.js +4 -4
  18. package/enum/BulkImportStatusEnum.js +6 -6
  19. package/enum/EntityTypeEnum.js +12 -11
  20. package/enum/FeatureTypeEnum.js +6 -6
  21. package/enum/GenderEnum.js +7 -7
  22. package/enum/NotificationStatusEnum.js +5 -5
  23. package/enum/NotificationTypeEnum.js +9 -9
  24. package/enum/OrderActionStatusEnum.js +7 -7
  25. package/enum/OrderStatusEnum.js +7 -7
  26. package/enum/PackageBoxTypeEnum.js +6 -6
  27. package/enum/PaymentMethodEnum.js +6 -6
  28. package/enum/PaymentStatusEnum.js +6 -6
  29. package/enum/PaymentTypeEnum.js +6 -6
  30. package/enum/PlatformEnum.js +4 -4
  31. package/enum/ReasonTypeEnum.js +6 -6
  32. package/enum/RegistrationStatusEnum.js +5 -5
  33. package/enum/SortByEnum.js +7 -7
  34. package/enum/SubscriptionStatusEnum.js +7 -7
  35. package/index.js +28 -28
  36. package/model/Address.js +95 -95
  37. package/model/AttributeType.js +50 -50
  38. package/model/AttributeValue.js +64 -64
  39. package/model/Banner.js +78 -78
  40. package/model/Brand.js +76 -76
  41. package/model/Cart.js +76 -76
  42. package/model/Category.js +72 -72
  43. package/model/CategoryAttributeType.js +62 -62
  44. package/model/Colour.js +52 -52
  45. package/model/Customer.js +94 -94
  46. package/model/DeviceToken.js +51 -51
  47. package/model/Document.js +73 -73
  48. package/model/DynamicUIComponent.js +52 -52
  49. package/model/Feedback.js +79 -79
  50. package/model/Inventory.js +87 -87
  51. package/model/NotificationHistory.js +67 -67
  52. package/model/Order.js +84 -84
  53. package/model/OrderActionReason.js +99 -99
  54. package/model/OrderItem.js +98 -98
  55. package/model/OrderItemHistory.js +69 -69
  56. package/model/OrderStatus.js +48 -48
  57. package/model/PackagingBox.js +78 -78
  58. package/model/Payment.js +101 -101
  59. package/model/PaymentMethod.js +36 -36
  60. package/model/PaymentStatus.js +36 -36
  61. package/model/PaymentType.js +36 -36
  62. package/model/Permission.js +55 -55
  63. package/model/Product.js +97 -97
  64. package/model/ProductGroup.js +48 -48
  65. package/model/ProductImport.js +55 -55
  66. package/model/ProductImportFailureAudits.js +57 -57
  67. package/model/ProductSpecification.js +65 -65
  68. package/model/ProductVariant.js +111 -111
  69. package/model/ProductVariantAttribute.js +58 -58
  70. package/model/ReasonContextMapping.js +70 -70
  71. package/model/ReasonMaster.js +74 -74
  72. package/model/Role.js +61 -61
  73. package/model/RolePermissionMapping.js +63 -63
  74. package/model/SpecificationType.js +41 -41
  75. package/model/Store.js +99 -99
  76. package/model/StoreUserMapping.js +44 -44
  77. package/model/SubscriptionFeature.js +53 -53
  78. package/model/SubscriptionPlan.js +70 -70
  79. package/model/SubscriptionPlanFeature.js +48 -48
  80. package/model/Tenant.js +91 -91
  81. package/model/TenantSettings.js +47 -47
  82. package/model/TenantSubscription.js +73 -73
  83. package/model/User.js +132 -132
  84. package/model/WishList.js +62 -62
  85. package/package.json +30 -30
  86. package/scripts/QueryBuilder.js +162 -162
  87. package/utility/AppUtil.js +65 -65
  88. package/utility/DateUtil.js +55 -55
  89. package/utility/ExcelUtil.js +125 -125
  90. package/utility/LocationUtility.js +130 -130
  91. package/utility/OrderTimeFilterUtil.js +88 -88
  92. package/utility/PdfUtil.js +64 -64
  93. package/utility/QueryUtil.js +261 -261
  94. package/utility/Razorpay.js +65 -65
  95. package/utility/ResolveAccessMode.js +61 -61
  96. package/utility/VariantPriceUtil.js +54 -54
@@ -1,244 +1,244 @@
1
- const EntityTypeEnum = require('../enum/EntityTypeEnum');
2
- const StatusMessage = require('../constants/StatusMessageConstants');
3
- const AppUtil = require('../utility/AppUtil');
4
- const AppConstants = require('../constants/AppConstants')
5
-
6
- const tenantSettingsDocumentValidation = async (
7
- file,
8
- documentMetadata,
9
- FileUploadUtil,
10
- FILE_PATHS,
11
- logger
12
- ) => {
13
- if (documentMetadata !== undefined) {
14
- if (
15
- typeof documentMetadata !== AppConstants.OBJECT ||
16
- Array.isArray(documentMetadata)
17
- ) {
18
- logger.warn(
19
- "Validation Failed: documentMetadata must be a single object for this operation.",
20
- );
21
- throw new Error(StatusMessage.TENANT_SETTINGS_SINGLE_LOGO_ALLOWED);
22
- }
23
- logger.info("Uploading new files to storage before transaction");
24
- const uploadResult = await FileUploadUtil.uploadFilesToStorage(
25
- documentMetadata,
26
- file,
27
- FILE_PATHS.IMAGE_DIR,
28
- );
29
- return uploadResult
30
- }
31
- return [];
32
- };
33
-
34
- const getTenantSettingsById = (TenantSettings, Document, getPublicUrl, logger) => {
35
- return async (req, res) => {
36
- try {
37
- const { id } = req.params;
38
-
39
- const settings = await TenantSettings.findOne({
40
- where: {
41
- TenantID: id
42
- },
43
- attributes: ["TenantSettingID", "TenantID", "ThemeColour"],
44
- });
45
-
46
- if (!settings) {
47
- return AppUtil.generateResponse(
48
- 404,
49
- StatusMessage.FAILURE,
50
- StatusMessage.TENANT_SETTINGS_NOT_FOUND,
51
- null,
52
- res
53
- );
54
- }
55
- let logo = null;
56
- const document = await Document.findOne({
57
- where: {
58
- EntityType: EntityTypeEnum.TENANT_SETTINGS,
59
- EntityID: settings.TenantSettingID
60
- },
61
- order: [["SortOrder", "ASC"]]
62
- });
63
- if(document) {
64
- logo = {
65
- documentId: document.DocumentID,
66
- sortOrder: document.SortOrder,
67
- documentUrl: await getPublicUrl(document, logger)
68
- }
69
- }
70
- const formattedSettings = {
71
- TenantSettingID: settings.TenantSettingID,
72
- TenantID: settings.TenantID,
73
- ThemeColour: settings.ThemeColour,
74
- Logo: logo
75
- };
76
-
77
- return AppUtil.generateResponse(
78
- 200,
79
- StatusMessage.SUCCESS,
80
- null,
81
- formattedSettings,
82
- res
83
- );
84
-
85
- } catch (error) {
86
- logger.error("Error fetching tenant settings:", error);
87
- return AppUtil.generateResponse(
88
- 500,
89
- StatusMessage.FAILURE,
90
- StatusMessage.SERVER_ERROR,
91
- null,
92
- res
93
- );
94
- }
95
- }}
96
-
97
- const updateTenantSettings = (TenantSettings, multer, upload, FileUploadUtil, FILE_PATHS, reqUpdatedBy, sequelize, logger) => {
98
- return async (req, res) => {
99
- upload(req, res, async (err) => {
100
- if (err instanceof multer.MulterError || err) {
101
- logger.error('Upload Error:', err);
102
- return AppUtil.generateResponse(
103
- 400,
104
- StatusMessage.FAILURE,
105
- StatusMessage.TENANT_SETTINGS_IMAGE_UPLOAD_FAILED,
106
- null,
107
- res
108
- );
109
- }
110
-
111
- let transaction;
112
- let uploadedFilePath = [];
113
- try {
114
- let data;
115
- try {
116
- data = req.body.data ? JSON.parse(req.body.data) : req.body;
117
- } catch (error) {
118
- logger.error('Invalid JSON in request body', error);
119
- return AppUtil.generateResponse(
120
- 400,
121
- StatusMessage.FAILURE,
122
- StatusMessage.INVALID_JSON_FORMAT,
123
- null,
124
- res
125
- );
126
- }
127
-
128
- const {
129
- TenantSettingID,
130
- TenantID,
131
- ThemeColour,
132
- documentMetadata
133
- } = data;
134
-
135
- // Validation
136
- if (!TenantSettingID && !TenantID) {
137
- logger.warn('TenantSettingID or TenantID is required for update.');
138
- return AppUtil.generateResponse(
139
- 400,
140
- StatusMessage.FAILURE,
141
- StatusMessage.TENANT_SETTINGS_REQUIRED_FIELD,
142
- null,
143
- res
144
- );
145
- }
146
-
147
- // Find existing settings
148
- const whereClause = TenantSettingID ? { TenantSettingID } : { TenantID };
149
- const existingSettings = await TenantSettings.findOne({ where: whereClause });
150
-
151
- if (!existingSettings) {
152
- logger.warn('Tenant settings not found for update', whereClause);
153
- return AppUtil.generateResponse(
154
- 404,
155
- StatusMessage.FAILURE,
156
- StatusMessage.TENANT_SETTINGS_NOT_FOUND,
157
- null,
158
- res
159
- );
160
- }
161
-
162
- // Upload new file to storage before starting transaction
163
- const uploadResult = await tenantSettingsDocumentValidation(req.files, documentMetadata, FileUploadUtil, FILE_PATHS, logger)
164
- if(uploadResult.length > 0) {
165
- uploadedFilePath = uploadResult.map(result => result.path)
166
- }
167
-
168
- // Start database transaction
169
- transaction = await sequelize.transaction();
170
-
171
- // Update tenant settings
172
- const updatePayload = {};
173
- if (ThemeColour !== undefined) updatePayload.ThemeColour = ThemeColour;
174
- let updatedBy = null
175
- if(reqUpdatedBy) {
176
- updatedBy = reqUpdatedBy;
177
- }
178
- else {
179
- updatedBy = req.user.UserID
180
- }
181
- updatePayload.UpdatedBy = updatedBy
182
- updatePayload.UpdatedAt = new Date();
183
-
184
- await existingSettings.update(updatePayload, { transaction });
185
-
186
- // Save/Update documents (handles both create and replace logic)
187
- if (uploadResult.length > 0) {
188
- logger.info('Saving document records for TenantSettingID:', existingSettings.TenantSettingID);
189
-
190
- await FileUploadUtil.saveDocumentRecords(
191
- uploadResult,
192
- EntityTypeEnum.TENANT_SETTINGS,
193
- existingSettings.TenantSettingID,
194
- existingSettings.TenantID,
195
- updatedBy,
196
- transaction
197
- );
198
- }
199
-
200
- await transaction.commit();
201
- logger.info('Tenant settings updated successfully');
202
-
203
- return AppUtil.generateResponse(
204
- 200,
205
- StatusMessage.SUCCESS,
206
- StatusMessage.TENANT_SETTINGS_UPDATED_SUCCESS,
207
- null,
208
- res
209
- );
210
-
211
- } catch (error) {
212
- if (transaction) await transaction.rollback();
213
-
214
- // Cleanup newly uploaded files if transaction failed
215
- if (uploadedFilePath.length > 0) {
216
- logger.info('Cleaning up uploaded files due to error');
217
- await FileUploadUtil.cleanupFiles(uploadedFilePath);
218
- }
219
- const errorMessages = [
220
- StatusMessage.INVALID_SORT_ORDER,
221
- StatusMessage.FILE_NOT_FOUND,
222
- StatusMessage.INVALID_FILE_UPLOAD_INPUT,
223
- StatusMessage.TENANT_SETTINGS_SINGLE_LOGO_ALLOWED,
224
- ];
225
- // Error handling
226
- if (errorMessages.includes(error.message)) {
227
- return AppUtil.generateResponse(400, StatusMessage.FAILURE, error.message, null, res);
228
- }
229
- if (error.name === 'SequelizeUniqueConstraintError') {
230
- return AppUtil.generateResponse(400, StatusMessage.FAILURE, StatusMessage.TENANT_SETTINGS_ALREADY_EXISTS, null, res);
231
- } else if (error.name === 'SequelizeValidationError') {
232
- const details = error.errors.map((e) => e.message);
233
- logger.warn(`Validation Error detected: ${details.join('; ')}`);
234
- return AppUtil.generateResponse(400, StatusMessage.FAILURE, StatusMessage.INVALID_REQUEST, null, res);
235
- } else {
236
- logger.error("Error in updateTenantSettings:", error);
237
- return AppUtil.generateResponse(500, StatusMessage.FAILURE, StatusMessage.TENANT_SETTINGS_UPDATE_ERROR, null, res);
238
- }
239
- }
240
- });
241
- };
242
- }
243
- module.exports = {getTenantSettingsById, updateTenantSettings, tenantSettingsDocumentValidation};
1
+ const EntityTypeEnum = require('../enum/EntityTypeEnum');
2
+ const StatusMessage = require('../constants/StatusMessageConstants');
3
+ const AppUtil = require('../utility/AppUtil');
4
+ const AppConstants = require('../constants/AppConstants')
5
+
6
+ const tenantSettingsDocumentValidation = async (
7
+ file,
8
+ documentMetadata,
9
+ FileUploadUtil,
10
+ FILE_PATHS,
11
+ logger
12
+ ) => {
13
+ if (documentMetadata !== undefined) {
14
+ if (
15
+ typeof documentMetadata !== AppConstants.OBJECT ||
16
+ Array.isArray(documentMetadata)
17
+ ) {
18
+ logger.warn(
19
+ "Validation Failed: documentMetadata must be a single object for this operation.",
20
+ );
21
+ throw new Error(StatusMessage.TENANT_SETTINGS_SINGLE_LOGO_ALLOWED);
22
+ }
23
+ logger.info("Uploading new files to storage before transaction");
24
+ const uploadResult = await FileUploadUtil.uploadFilesToStorage(
25
+ documentMetadata,
26
+ file,
27
+ FILE_PATHS.IMAGE_DIR,
28
+ );
29
+ return uploadResult
30
+ }
31
+ return [];
32
+ };
33
+
34
+ const getTenantSettingsById = (TenantSettings, Document, getPublicUrl, logger) => {
35
+ return async (req, res) => {
36
+ try {
37
+ const { id } = req.params;
38
+
39
+ const settings = await TenantSettings.findOne({
40
+ where: {
41
+ TenantID: id
42
+ },
43
+ attributes: ["TenantSettingID", "TenantID", "ThemeColour"],
44
+ });
45
+
46
+ if (!settings) {
47
+ return AppUtil.generateResponse(
48
+ 404,
49
+ StatusMessage.FAILURE,
50
+ StatusMessage.TENANT_SETTINGS_NOT_FOUND,
51
+ null,
52
+ res
53
+ );
54
+ }
55
+ let logo = null;
56
+ const document = await Document.findOne({
57
+ where: {
58
+ EntityType: EntityTypeEnum.TENANT_SETTINGS,
59
+ EntityID: settings.TenantSettingID
60
+ },
61
+ order: [["SortOrder", "ASC"]]
62
+ });
63
+ if(document) {
64
+ logo = {
65
+ documentId: document.DocumentID,
66
+ sortOrder: document.SortOrder,
67
+ documentUrl: await getPublicUrl(document, logger)
68
+ }
69
+ }
70
+ const formattedSettings = {
71
+ TenantSettingID: settings.TenantSettingID,
72
+ TenantID: settings.TenantID,
73
+ ThemeColour: settings.ThemeColour,
74
+ Logo: logo
75
+ };
76
+
77
+ return AppUtil.generateResponse(
78
+ 200,
79
+ StatusMessage.SUCCESS,
80
+ null,
81
+ formattedSettings,
82
+ res
83
+ );
84
+
85
+ } catch (error) {
86
+ logger.error("Error fetching tenant settings:", error);
87
+ return AppUtil.generateResponse(
88
+ 500,
89
+ StatusMessage.FAILURE,
90
+ StatusMessage.SERVER_ERROR,
91
+ null,
92
+ res
93
+ );
94
+ }
95
+ }}
96
+
97
+ const updateTenantSettings = (TenantSettings, multer, upload, FileUploadUtil, FILE_PATHS, reqUpdatedBy, sequelize, logger) => {
98
+ return async (req, res) => {
99
+ upload(req, res, async (err) => {
100
+ if (err instanceof multer.MulterError || err) {
101
+ logger.error('Upload Error:', err);
102
+ return AppUtil.generateResponse(
103
+ 400,
104
+ StatusMessage.FAILURE,
105
+ StatusMessage.TENANT_SETTINGS_IMAGE_UPLOAD_FAILED,
106
+ null,
107
+ res
108
+ );
109
+ }
110
+
111
+ let transaction;
112
+ let uploadedFilePath = [];
113
+ try {
114
+ let data;
115
+ try {
116
+ data = req.body.data ? JSON.parse(req.body.data) : req.body;
117
+ } catch (error) {
118
+ logger.error('Invalid JSON in request body', error);
119
+ return AppUtil.generateResponse(
120
+ 400,
121
+ StatusMessage.FAILURE,
122
+ StatusMessage.INVALID_JSON_FORMAT,
123
+ null,
124
+ res
125
+ );
126
+ }
127
+
128
+ const {
129
+ TenantSettingID,
130
+ TenantID,
131
+ ThemeColour,
132
+ documentMetadata
133
+ } = data;
134
+
135
+ // Validation
136
+ if (!TenantSettingID && !TenantID) {
137
+ logger.warn('TenantSettingID or TenantID is required for update.');
138
+ return AppUtil.generateResponse(
139
+ 400,
140
+ StatusMessage.FAILURE,
141
+ StatusMessage.TENANT_SETTINGS_REQUIRED_FIELD,
142
+ null,
143
+ res
144
+ );
145
+ }
146
+
147
+ // Find existing settings
148
+ const whereClause = TenantSettingID ? { TenantSettingID } : { TenantID };
149
+ const existingSettings = await TenantSettings.findOne({ where: whereClause });
150
+
151
+ if (!existingSettings) {
152
+ logger.warn('Tenant settings not found for update', whereClause);
153
+ return AppUtil.generateResponse(
154
+ 404,
155
+ StatusMessage.FAILURE,
156
+ StatusMessage.TENANT_SETTINGS_NOT_FOUND,
157
+ null,
158
+ res
159
+ );
160
+ }
161
+
162
+ // Upload new file to storage before starting transaction
163
+ const uploadResult = await tenantSettingsDocumentValidation(req.files, documentMetadata, FileUploadUtil, FILE_PATHS, logger)
164
+ if(uploadResult.length > 0) {
165
+ uploadedFilePath = uploadResult.map(result => result.path)
166
+ }
167
+
168
+ // Start database transaction
169
+ transaction = await sequelize.transaction();
170
+
171
+ // Update tenant settings
172
+ const updatePayload = {};
173
+ if (ThemeColour !== undefined) updatePayload.ThemeColour = ThemeColour;
174
+ let updatedBy = null
175
+ if(reqUpdatedBy) {
176
+ updatedBy = reqUpdatedBy;
177
+ }
178
+ else {
179
+ updatedBy = req.user.UserID
180
+ }
181
+ updatePayload.UpdatedBy = updatedBy
182
+ updatePayload.UpdatedAt = new Date();
183
+
184
+ await existingSettings.update(updatePayload, { transaction });
185
+
186
+ // Save/Update documents (handles both create and replace logic)
187
+ if (uploadResult.length > 0) {
188
+ logger.info('Saving document records for TenantSettingID:', existingSettings.TenantSettingID);
189
+
190
+ await FileUploadUtil.saveDocumentRecords(
191
+ uploadResult,
192
+ EntityTypeEnum.TENANT_SETTINGS,
193
+ existingSettings.TenantSettingID,
194
+ existingSettings.TenantID,
195
+ updatedBy,
196
+ transaction
197
+ );
198
+ }
199
+
200
+ await transaction.commit();
201
+ logger.info('Tenant settings updated successfully');
202
+
203
+ return AppUtil.generateResponse(
204
+ 200,
205
+ StatusMessage.SUCCESS,
206
+ StatusMessage.TENANT_SETTINGS_UPDATED_SUCCESS,
207
+ null,
208
+ res
209
+ );
210
+
211
+ } catch (error) {
212
+ if (transaction) await transaction.rollback();
213
+
214
+ // Cleanup newly uploaded files if transaction failed
215
+ if (uploadedFilePath.length > 0) {
216
+ logger.info('Cleaning up uploaded files due to error');
217
+ await FileUploadUtil.cleanupFiles(uploadedFilePath);
218
+ }
219
+ const errorMessages = [
220
+ StatusMessage.INVALID_SORT_ORDER,
221
+ StatusMessage.FILE_NOT_FOUND,
222
+ StatusMessage.INVALID_FILE_UPLOAD_INPUT,
223
+ StatusMessage.TENANT_SETTINGS_SINGLE_LOGO_ALLOWED,
224
+ ];
225
+ // Error handling
226
+ if (errorMessages.includes(error.message)) {
227
+ return AppUtil.generateResponse(400, StatusMessage.FAILURE, error.message, null, res);
228
+ }
229
+ if (error.name === 'SequelizeUniqueConstraintError') {
230
+ return AppUtil.generateResponse(400, StatusMessage.FAILURE, StatusMessage.TENANT_SETTINGS_ALREADY_EXISTS, null, res);
231
+ } else if (error.name === 'SequelizeValidationError') {
232
+ const details = error.errors.map((e) => e.message);
233
+ logger.warn(`Validation Error detected: ${details.join('; ')}`);
234
+ return AppUtil.generateResponse(400, StatusMessage.FAILURE, StatusMessage.INVALID_REQUEST, null, res);
235
+ } else {
236
+ logger.error("Error in updateTenantSettings:", error);
237
+ return AppUtil.generateResponse(500, StatusMessage.FAILURE, StatusMessage.TENANT_SETTINGS_UPDATE_ERROR, null, res);
238
+ }
239
+ }
240
+ });
241
+ };
242
+ }
243
+ module.exports = {getTenantSettingsById, updateTenantSettings, tenantSettingsDocumentValidation};
244
244