@b2y/ecommerce-common 1.1.4 → 1.1.5

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 (80) hide show
  1. package/README.md +4 -4
  2. package/constants/AppConstants.js +6 -6
  3. package/constants/ReportConstants.js +14 -14
  4. package/constants/StatusMessageConstants.js +17 -17
  5. package/dbconnection/Connect.js +432 -432
  6. package/enum/AccessModeEnum.js +7 -7
  7. package/enum/AddressTypeEnum.js +6 -6
  8. package/enum/BillingCycleEnum.js +5 -5
  9. package/enum/BooleanEnum.js +4 -4
  10. package/enum/BulkImportStatusEnum.js +6 -6
  11. package/enum/EntityTypeEnum.js +11 -11
  12. package/enum/FeatureTypeEnum.js +6 -6
  13. package/enum/GenderEnum.js +7 -7
  14. package/enum/NotificationStatusEnum.js +5 -5
  15. package/enum/NotificationTypeEnum.js +9 -9
  16. package/enum/OrderStatusEnum.js +7 -7
  17. package/enum/PaymentMethodEnum.js +6 -6
  18. package/enum/PaymentStatusEnum.js +6 -6
  19. package/enum/PaymentTypeEnum.js +6 -6
  20. package/enum/PlatformEnum.js +4 -4
  21. package/enum/RegistrationStatusEnum.js +5 -5
  22. package/enum/SortByEnum.js +7 -7
  23. package/enum/SubscriptionStatusEnum.js +7 -7
  24. package/index.js +22 -22
  25. package/model/Address.js +95 -95
  26. package/model/AttributeType.js +50 -50
  27. package/model/AttributeValue.js +64 -64
  28. package/model/Banner.js +78 -78
  29. package/model/Brand.js +76 -76
  30. package/model/Cart.js +76 -76
  31. package/model/Category.js +72 -72
  32. package/model/CategoryAttributeType.js +62 -62
  33. package/model/Colour.js +52 -52
  34. package/model/Customer.js +94 -94
  35. package/model/DeviceToken.js +51 -51
  36. package/model/Document.js +73 -73
  37. package/model/DynamicUIComponent.js +52 -52
  38. package/model/Feedback.js +79 -79
  39. package/model/Inventory.js +83 -83
  40. package/model/NotificationHistory.js +67 -67
  41. package/model/Order.js +94 -94
  42. package/model/OrderItem.js +98 -98
  43. package/model/OrderItemHistory.js +69 -69
  44. package/model/OrderStatus.js +48 -48
  45. package/model/Payment.js +101 -101
  46. package/model/PaymentMethod.js +36 -36
  47. package/model/PaymentStatus.js +36 -36
  48. package/model/PaymentType.js +36 -36
  49. package/model/Permission.js +55 -55
  50. package/model/Product.js +87 -82
  51. package/model/ProductGroup.js +48 -48
  52. package/model/ProductImport.js +55 -55
  53. package/model/ProductImportFailureAudits.js +57 -57
  54. package/model/ProductSpecification.js +65 -65
  55. package/model/ProductVariant.js +75 -75
  56. package/model/ProductVariantAttribute.js +58 -58
  57. package/model/Role.js +61 -61
  58. package/model/RolePermissionMapping.js +63 -63
  59. package/model/SpecificationType.js +41 -41
  60. package/model/Store.js +99 -99
  61. package/model/StoreUserMapping.js +44 -44
  62. package/model/SubscriptionFeature.js +49 -49
  63. package/model/SubscriptionPlan.js +66 -66
  64. package/model/SubscriptionPlanFeature.js +48 -48
  65. package/model/Tenant.js +91 -91
  66. package/model/TenantSettings.js +47 -47
  67. package/model/TenantSubscription.js +73 -73
  68. package/model/User.js +132 -132
  69. package/model/WishList.js +62 -62
  70. package/package.json +29 -29
  71. package/utility/AppUtil.js +65 -65
  72. package/utility/DateUtil.js +55 -55
  73. package/utility/ExcelUtil.js +125 -125
  74. package/utility/LocationUtility.js +130 -130
  75. package/utility/OrderTimeFilterUtil.js +88 -88
  76. package/utility/PdfUtil.js +64 -64
  77. package/utility/QueryUtil.js +261 -261
  78. package/utility/Razorpay.js +65 -65
  79. package/utility/ResolveAccessMode.js +38 -38
  80. package/utility/VariantPriceUtil.js +54 -54
@@ -1,432 +1,432 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const initializeModels = (sequelize) => {
4
- const models = {};
5
- const modelFiles = fs.readdirSync(path.join(__dirname, "../model"));
6
- modelFiles.forEach((file) => {
7
- const model = require(path.join(__dirname, "../model", file))(sequelize);
8
- models[model.name] = model;
9
- });
10
- const {
11
- Tenant,
12
- TenantSettings,
13
- User,
14
- Customer,
15
- Address,
16
- Product,
17
- ProductVariant,
18
- Category,
19
- Brand,
20
- Colour,
21
- Order,
22
- OrderItem,
23
- Payment,
24
- PaymentStatus,
25
- PaymentMethod,
26
- PaymentType,
27
- Feedback,
28
- Role,
29
- Permission,
30
- RolePermissionMapping,
31
- DeviceToken,
32
- NotificationHistory,
33
- DynamicUIComponent,
34
- ProductGroup,
35
- OrderStatus,
36
- Banner,
37
- Document,
38
- AttributeType,
39
- AttributeValue,
40
- Store,
41
- StoreUserMapping,
42
- OrderItemHistory,
43
- Inventory,
44
- SpecificationType,
45
- ProductSpecification,
46
- ProductVariantAttribute,
47
- Cart,
48
- WishList,
49
- SubscriptionPlan,
50
- SubscriptionFeature,
51
- SubscriptionPlanFeature,
52
- TenantSubscription,
53
- ProductImport,
54
- ProductImportFailureAudits
55
- } = models;
56
- Category.hasMany(Category, {
57
- foreignKey: "ParentCategoryID",
58
- as: "subCategories",
59
- });
60
-
61
- Category.belongsTo(Category, {
62
- foreignKey: "ParentCategoryID",
63
- as: "parentCategory",
64
- });
65
-
66
-
67
- Store.belongsToMany(User, {
68
- through: StoreUserMapping,
69
- foreignKey: "StoreID",
70
- otherKey: "UserID",
71
- as: "User",
72
- });
73
-
74
- User.belongsToMany(Store, {
75
- through: StoreUserMapping,
76
- foreignKey: "UserID",
77
- otherKey: "StoreID",
78
- as: "Store",
79
- });
80
-
81
- //permissions
82
- // Role to Permission (many-to-many through RolePermissionMapping)
83
- Role.belongsToMany(Permission, {
84
- through: RolePermissionMapping,
85
- foreignKey: "RoleID",
86
- otherKey: "PermissionID",
87
- as: "Permission",
88
- });
89
-
90
- Permission.belongsToMany(Role, {
91
- through: RolePermissionMapping,
92
- foreignKey: "PermissionID",
93
- otherKey: "RoleID",
94
- as: "Role",
95
- });
96
-
97
- // User to Roles association
98
- User.belongsTo(Role, { foreignKey: "RoleID", as: "UserRole" });
99
- Role.hasMany(User, { foreignKey: "RoleID" });
100
-
101
- /*---- users realted associations ----*/
102
- // Tenant and UserManagement (One-to-many: A Tenant has many UserManagement entries)
103
- Tenant.hasMany(User, { foreignKey: "TenantID", as: "User" });
104
- User.belongsTo(Tenant, { foreignKey: "TenantID", as: "Tenant" });
105
-
106
- // Tenant and Order
107
- Order.belongsTo(Tenant, { foreignKey: 'TenantID', as: 'Tenant' });
108
- Tenant.hasMany(Order, { foreignKey: 'TenantID', as: 'Order' });
109
-
110
- // Tenant and Customer (One-to-many: A Tenant has many Customers)
111
- Tenant.hasMany(Customer, { foreignKey: "TenantID", as: "Customer" });
112
- Customer.belongsTo(Tenant, { foreignKey: "TenantID", as: "Tenant" });
113
-
114
- Address.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
115
- Customer.hasMany(Address, { foreignKey: "CustomerID", as: "Address" });
116
-
117
-
118
- /*---- product related associations -----*/
119
- // Product and ProductVariant Associations
120
- // One-to-Many
121
- Product.hasMany(ProductVariant, {
122
- foreignKey: "ProductID",
123
- as: "ProductVariant",
124
- });
125
- ProductVariant.belongsTo(Product, {
126
- foreignKey: "ProductID",
127
- as: "Product",
128
- });
129
-
130
- // Product and Category Association
131
- // Many-to-One
132
- Product.belongsTo(Category, { foreignKey: "CategoryID", as: "Category" });
133
- Category.hasMany(Product, { foreignKey: "CategoryID", as: "Product" });
134
-
135
- // Product and Brand Association
136
- // Many-to-One
137
- Product.belongsTo(Brand, { foreignKey: "BrandID", as: "Brand" });
138
-
139
- // Brand model definition
140
- Brand.hasMany(Product, {
141
- foreignKey: "BrandID", // Make sure the foreign key matches in both models
142
- as: "Product",
143
- });
144
-
145
- // ProductVariant and ProductVariantAttribute
146
- ProductVariant.belongsToMany(AttributeValue, {
147
- through: ProductVariantAttribute,
148
- foreignKey: "ProductVariantID",
149
- otherKey: "AttributeValueID",
150
- as: "AttributeValues",
151
- });
152
-
153
- AttributeValue.belongsToMany(ProductVariant, {
154
- through: ProductVariantAttribute,
155
- foreignKey: "AttributeValueID",
156
- otherKey: "ProductVariantID",
157
- as: "ProductVariants",
158
- });
159
-
160
- ProductVariant.hasMany(ProductVariantAttribute, {
161
- foreignKey: "ProductVariantID",
162
- as: "VariantAttributes",
163
- });
164
- ProductVariantAttribute.belongsTo(ProductVariant, {
165
- foreignKey: "ProductVariantID",
166
- as: "Variant",
167
- });
168
-
169
- // AttributeValue and ProductVariantAttribute
170
- AttributeValue.hasMany(ProductVariantAttribute, {
171
- foreignKey: "AttributeValueID",
172
- as: "VariantAttributes",
173
- });
174
- ProductVariantAttribute.belongsTo(AttributeValue, {
175
- foreignKey: "AttributeValueID",
176
- as: "AttributeValue",
177
- });
178
-
179
- // Product and ProductGroup Association
180
- // Many-to-One
181
- Product.belongsTo(ProductGroup, {
182
- foreignKey: "ProductGroupID",
183
- as: "ProductGroup",
184
- });
185
- ProductGroup.hasMany(Product, {
186
- foreignKey: "ProductGroupID",
187
- as: "Product",
188
- });
189
-
190
- // Order
191
- Order.belongsTo(Customer, {
192
- foreignKey: "CustomerID",
193
- as: "Customer",
194
- });
195
-
196
- Order.belongsTo(Address, {
197
- foreignKey: "AddressID",
198
- as: "Address",
199
- });
200
-
201
- Order.hasMany(OrderItem, {
202
- foreignKey: "OrderID",
203
- as: "OrderItem",
204
- });
205
- Order.hasMany(Payment, {
206
- foreignKey: "OrderID",
207
- as: "Payment",
208
- });
209
-
210
- // OrderItem
211
- OrderItem.belongsTo(Order, {
212
- foreignKey: "OrderID",
213
- as: "Order",
214
- });
215
-
216
- OrderItem.belongsTo(ProductVariant, {
217
- foreignKey: "ProductVariantID",
218
- as: "ProductVariant",
219
- });
220
-
221
- // OrderItem to Store association
222
- OrderItem.belongsTo(Store, {
223
- foreignKey: "StoreID",
224
- as: "Store",
225
- });
226
-
227
- Store.hasMany(OrderItem, {
228
- foreignKey: "StoreID",
229
- as: "OrderItem",
230
- });
231
-
232
- OrderItem.belongsTo(OrderStatus, {
233
- foreignKey: "OrderStatusID",
234
- as: "OrderItemStatus",
235
- });
236
- OrderStatus.hasMany(OrderItem, {
237
- foreignKey: "OrderStatusID",
238
- as: "OrderItem",
239
- });
240
- // OrderItem to OrderItemHistory association
241
- OrderItem.hasMany(OrderItemHistory, {
242
- foreignKey: "OrderItemID",
243
- as: "OrderItemHistory",
244
- });
245
-
246
- // OrderItem to Feedback
247
- OrderItem.hasMany(Feedback, {
248
- foreignKey: "OrderItemID",
249
- as: "Feedback",
250
- });
251
- OrderItemHistory.belongsTo(OrderItem, {
252
- foreignKey: "OrderItemID",
253
- as: "OrderItem",
254
- });
255
-
256
- // OrderItemHistory to OrderStatus association
257
- OrderItemHistory.belongsTo(OrderStatus, {
258
- foreignKey: "OrderStatusID",
259
- as: "OrderItemStatus",
260
- });
261
- OrderStatus.hasMany(OrderItemHistory, {
262
- foreignKey: "OrderStatusID",
263
- as: "OrderItemStatus",
264
- });
265
-
266
- // OrderStatus to Colour
267
- OrderStatus.belongsTo(Colour, {
268
- foreignKey: "ColourID",
269
- as: "Colour",
270
- });
271
- //Payment
272
- Payment.belongsTo(Order, {
273
- foreignKey: "OrderID",
274
- as: "Order",
275
- });
276
- Payment.belongsTo(PaymentStatus, {
277
- foreignKey: "PaymentStatusID",
278
- as: "PaymentStatus",
279
- });
280
- Payment.belongsTo(PaymentMethod, {
281
- foreignKey: "PaymentMethodID",
282
- as: "PaymentMethod",
283
- });
284
- Payment.belongsTo(PaymentType, {
285
- foreignKey: "PaymentTypeID",
286
- as: "PaymentType",
287
- });
288
-
289
- // Feedback Associations
290
- Feedback.belongsTo(Product, { foreignKey: "ProductID", as: "Product" });
291
- Feedback.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
292
- Feedback.belongsTo(OrderItem, {
293
- foreignKey: "OrderItemID",
294
- as: "OrderItem",
295
- });
296
-
297
- //
298
- Product.hasMany(Feedback, { foreignKey: "ProductID", as: "Feedback" });
299
- Customer.hasMany(Feedback, { foreignKey: "CustomerID", as: "Feedback" });
300
-
301
- Customer.hasMany(Order, {
302
- foreignKey: "CustomerID",
303
- as: "Orders",
304
- });
305
-
306
- ProductVariant.hasMany(OrderItem, {
307
- foreignKey: "ProductVariantID",
308
- as: "OrderItems",
309
- });
310
-
311
- // One-to-Many: AttributeType has many Attributes
312
- AttributeType.hasMany(AttributeValue, {
313
- foreignKey: "AttributeTypeID",
314
- as: "AttributeValue",
315
- });
316
-
317
- // Many-to-One: Attribute belongs to an AttributeType
318
- AttributeValue.belongsTo(AttributeType, {
319
- foreignKey: "AttributeTypeID",
320
- as: "AttributeType",
321
- });
322
-
323
- // ProductVariant and Inventory association
324
- ProductVariant.hasMany(Inventory, {
325
- foreignKey: "ProductVariantID",
326
- as: "Inventory",
327
- });
328
-
329
- Inventory.belongsTo(ProductVariant, {
330
- foreignKey: "ProductVariantID",
331
- as: "ProductVariant",
332
- });
333
-
334
- // Inventory and Store association
335
- Inventory.belongsTo(Store, {
336
- foreignKey: "StoreID",
337
- as: "Store",
338
- });
339
-
340
- ProductSpecification.belongsTo(SpecificationType, {
341
- foreignKey: "SpecificationTypeID",
342
- as: "SpecificationType",
343
- });
344
-
345
- SpecificationType.hasMany(ProductSpecification, {
346
- foreignKey: "SpecificationTypeID",
347
- as: "ProductSpecifications",
348
- });
349
-
350
- Product.belongsToMany(SpecificationType, {
351
- through: ProductSpecification, // join model
352
- foreignKey: "ProductID",
353
- otherKey: "SpecificationTypeID",
354
- as: "SpecificationTypes",
355
- });
356
-
357
- SpecificationType.belongsToMany(Product, {
358
- through: ProductSpecification,
359
- foreignKey: "SpecificationTypeID",
360
- otherKey: "ProductID",
361
- as: "Products",
362
- });
363
-
364
- //wishlist association
365
- WishList.belongsTo(ProductVariant, {
366
- foreignKey: "ProductVariantID",
367
- as: "ProductVariant",
368
- });
369
-
370
- WishList.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
371
- ProductVariant.hasMany(WishList, {
372
- foreignKey: "ProductVariantID",
373
- as: "WishList",
374
- });
375
-
376
- Customer.hasMany(WishList, { foreignKey: "CustomerID", as: "WishList" });
377
-
378
- // Cart and ProductVariant Association
379
- Cart.belongsTo(ProductVariant, {
380
- foreignKey: "ProductVariantID",
381
- as: "ProductVariant",
382
- });
383
-
384
- Cart.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
385
-
386
- Cart.belongsTo(Inventory, { foreignKey: "InventoryID", as: "Inventory" });
387
-
388
- // subscription
389
- // SubscriptionPlan and SubscriptionFeature
390
- SubscriptionPlan.belongsToMany(SubscriptionFeature, {
391
- through: SubscriptionPlanFeature,
392
- foreignKey: "SubscriptionPlanID",
393
- otherKey: "SubscriptionFeatureID",
394
- as: "Features",
395
- });
396
-
397
- SubscriptionFeature.belongsToMany(SubscriptionPlan, {
398
- through: SubscriptionPlanFeature,
399
- foreignKey: "SubscriptionFeatureID",
400
- otherKey: "SubscriptionPlanID",
401
- as: "SubscriptionPlans",
402
- });
403
-
404
- // SubscriptionPlan and Tenant
405
- Tenant.hasOne(TenantSubscription, {
406
- foreignKey: "TenantID",
407
- as: "CurrentSubscription",
408
- });
409
-
410
- TenantSubscription.belongsTo(models.Tenant, {
411
- foreignKey: "TenantID",
412
- as: "SubscribedTenant",
413
- });
414
-
415
- TenantSubscription.belongsTo(models.SubscriptionPlan, {
416
- foreignKey: "SubscriptionPlanID",
417
- as: "SubscriptionPlan",
418
- });
419
-
420
- // ProductImport and ProductImportFailureAudits
421
- ProductImport.hasMany(ProductImportFailureAudits, {
422
- foreignKey: 'ProductImportID',
423
- as: "ProductImportFailureAudits",
424
- });
425
-
426
- ProductImportFailureAudits.belongsTo(ProductImport, {
427
- foreignKey: 'ProductImportID',
428
- as: 'ProductImport'
429
- })
430
- return { ...models };
431
- };
432
- module.exports = initializeModels;
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const initializeModels = (sequelize) => {
4
+ const models = {};
5
+ const modelFiles = fs.readdirSync(path.join(__dirname, "../model"));
6
+ modelFiles.forEach((file) => {
7
+ const model = require(path.join(__dirname, "../model", file))(sequelize);
8
+ models[model.name] = model;
9
+ });
10
+ const {
11
+ Tenant,
12
+ TenantSettings,
13
+ User,
14
+ Customer,
15
+ Address,
16
+ Product,
17
+ ProductVariant,
18
+ Category,
19
+ Brand,
20
+ Colour,
21
+ Order,
22
+ OrderItem,
23
+ Payment,
24
+ PaymentStatus,
25
+ PaymentMethod,
26
+ PaymentType,
27
+ Feedback,
28
+ Role,
29
+ Permission,
30
+ RolePermissionMapping,
31
+ DeviceToken,
32
+ NotificationHistory,
33
+ DynamicUIComponent,
34
+ ProductGroup,
35
+ OrderStatus,
36
+ Banner,
37
+ Document,
38
+ AttributeType,
39
+ AttributeValue,
40
+ Store,
41
+ StoreUserMapping,
42
+ OrderItemHistory,
43
+ Inventory,
44
+ SpecificationType,
45
+ ProductSpecification,
46
+ ProductVariantAttribute,
47
+ Cart,
48
+ WishList,
49
+ SubscriptionPlan,
50
+ SubscriptionFeature,
51
+ SubscriptionPlanFeature,
52
+ TenantSubscription,
53
+ ProductImport,
54
+ ProductImportFailureAudits
55
+ } = models;
56
+ Category.hasMany(Category, {
57
+ foreignKey: "ParentCategoryID",
58
+ as: "subCategories",
59
+ });
60
+
61
+ Category.belongsTo(Category, {
62
+ foreignKey: "ParentCategoryID",
63
+ as: "parentCategory",
64
+ });
65
+
66
+
67
+ Store.belongsToMany(User, {
68
+ through: StoreUserMapping,
69
+ foreignKey: "StoreID",
70
+ otherKey: "UserID",
71
+ as: "User",
72
+ });
73
+
74
+ User.belongsToMany(Store, {
75
+ through: StoreUserMapping,
76
+ foreignKey: "UserID",
77
+ otherKey: "StoreID",
78
+ as: "Store",
79
+ });
80
+
81
+ //permissions
82
+ // Role to Permission (many-to-many through RolePermissionMapping)
83
+ Role.belongsToMany(Permission, {
84
+ through: RolePermissionMapping,
85
+ foreignKey: "RoleID",
86
+ otherKey: "PermissionID",
87
+ as: "Permission",
88
+ });
89
+
90
+ Permission.belongsToMany(Role, {
91
+ through: RolePermissionMapping,
92
+ foreignKey: "PermissionID",
93
+ otherKey: "RoleID",
94
+ as: "Role",
95
+ });
96
+
97
+ // User to Roles association
98
+ User.belongsTo(Role, { foreignKey: "RoleID", as: "UserRole" });
99
+ Role.hasMany(User, { foreignKey: "RoleID" });
100
+
101
+ /*---- users realted associations ----*/
102
+ // Tenant and UserManagement (One-to-many: A Tenant has many UserManagement entries)
103
+ Tenant.hasMany(User, { foreignKey: "TenantID", as: "User" });
104
+ User.belongsTo(Tenant, { foreignKey: "TenantID", as: "Tenant" });
105
+
106
+ // Tenant and Order
107
+ Order.belongsTo(Tenant, { foreignKey: 'TenantID', as: 'Tenant' });
108
+ Tenant.hasMany(Order, { foreignKey: 'TenantID', as: 'Order' });
109
+
110
+ // Tenant and Customer (One-to-many: A Tenant has many Customers)
111
+ Tenant.hasMany(Customer, { foreignKey: "TenantID", as: "Customer" });
112
+ Customer.belongsTo(Tenant, { foreignKey: "TenantID", as: "Tenant" });
113
+
114
+ Address.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
115
+ Customer.hasMany(Address, { foreignKey: "CustomerID", as: "Address" });
116
+
117
+
118
+ /*---- product related associations -----*/
119
+ // Product and ProductVariant Associations
120
+ // One-to-Many
121
+ Product.hasMany(ProductVariant, {
122
+ foreignKey: "ProductID",
123
+ as: "ProductVariant",
124
+ });
125
+ ProductVariant.belongsTo(Product, {
126
+ foreignKey: "ProductID",
127
+ as: "Product",
128
+ });
129
+
130
+ // Product and Category Association
131
+ // Many-to-One
132
+ Product.belongsTo(Category, { foreignKey: "CategoryID", as: "Category" });
133
+ Category.hasMany(Product, { foreignKey: "CategoryID", as: "Product" });
134
+
135
+ // Product and Brand Association
136
+ // Many-to-One
137
+ Product.belongsTo(Brand, { foreignKey: "BrandID", as: "Brand" });
138
+
139
+ // Brand model definition
140
+ Brand.hasMany(Product, {
141
+ foreignKey: "BrandID", // Make sure the foreign key matches in both models
142
+ as: "Product",
143
+ });
144
+
145
+ // ProductVariant and ProductVariantAttribute
146
+ ProductVariant.belongsToMany(AttributeValue, {
147
+ through: ProductVariantAttribute,
148
+ foreignKey: "ProductVariantID",
149
+ otherKey: "AttributeValueID",
150
+ as: "AttributeValues",
151
+ });
152
+
153
+ AttributeValue.belongsToMany(ProductVariant, {
154
+ through: ProductVariantAttribute,
155
+ foreignKey: "AttributeValueID",
156
+ otherKey: "ProductVariantID",
157
+ as: "ProductVariants",
158
+ });
159
+
160
+ ProductVariant.hasMany(ProductVariantAttribute, {
161
+ foreignKey: "ProductVariantID",
162
+ as: "VariantAttributes",
163
+ });
164
+ ProductVariantAttribute.belongsTo(ProductVariant, {
165
+ foreignKey: "ProductVariantID",
166
+ as: "Variant",
167
+ });
168
+
169
+ // AttributeValue and ProductVariantAttribute
170
+ AttributeValue.hasMany(ProductVariantAttribute, {
171
+ foreignKey: "AttributeValueID",
172
+ as: "VariantAttributes",
173
+ });
174
+ ProductVariantAttribute.belongsTo(AttributeValue, {
175
+ foreignKey: "AttributeValueID",
176
+ as: "AttributeValue",
177
+ });
178
+
179
+ // Product and ProductGroup Association
180
+ // Many-to-One
181
+ Product.belongsTo(ProductGroup, {
182
+ foreignKey: "ProductGroupID",
183
+ as: "ProductGroup",
184
+ });
185
+ ProductGroup.hasMany(Product, {
186
+ foreignKey: "ProductGroupID",
187
+ as: "Product",
188
+ });
189
+
190
+ // Order
191
+ Order.belongsTo(Customer, {
192
+ foreignKey: "CustomerID",
193
+ as: "Customer",
194
+ });
195
+
196
+ Order.belongsTo(Address, {
197
+ foreignKey: "AddressID",
198
+ as: "Address",
199
+ });
200
+
201
+ Order.hasMany(OrderItem, {
202
+ foreignKey: "OrderID",
203
+ as: "OrderItem",
204
+ });
205
+ Order.hasMany(Payment, {
206
+ foreignKey: "OrderID",
207
+ as: "Payment",
208
+ });
209
+
210
+ // OrderItem
211
+ OrderItem.belongsTo(Order, {
212
+ foreignKey: "OrderID",
213
+ as: "Order",
214
+ });
215
+
216
+ OrderItem.belongsTo(ProductVariant, {
217
+ foreignKey: "ProductVariantID",
218
+ as: "ProductVariant",
219
+ });
220
+
221
+ // OrderItem to Store association
222
+ OrderItem.belongsTo(Store, {
223
+ foreignKey: "StoreID",
224
+ as: "Store",
225
+ });
226
+
227
+ Store.hasMany(OrderItem, {
228
+ foreignKey: "StoreID",
229
+ as: "OrderItem",
230
+ });
231
+
232
+ OrderItem.belongsTo(OrderStatus, {
233
+ foreignKey: "OrderStatusID",
234
+ as: "OrderItemStatus",
235
+ });
236
+ OrderStatus.hasMany(OrderItem, {
237
+ foreignKey: "OrderStatusID",
238
+ as: "OrderItem",
239
+ });
240
+ // OrderItem to OrderItemHistory association
241
+ OrderItem.hasMany(OrderItemHistory, {
242
+ foreignKey: "OrderItemID",
243
+ as: "OrderItemHistory",
244
+ });
245
+
246
+ // OrderItem to Feedback
247
+ OrderItem.hasMany(Feedback, {
248
+ foreignKey: "OrderItemID",
249
+ as: "Feedback",
250
+ });
251
+ OrderItemHistory.belongsTo(OrderItem, {
252
+ foreignKey: "OrderItemID",
253
+ as: "OrderItem",
254
+ });
255
+
256
+ // OrderItemHistory to OrderStatus association
257
+ OrderItemHistory.belongsTo(OrderStatus, {
258
+ foreignKey: "OrderStatusID",
259
+ as: "OrderItemStatus",
260
+ });
261
+ OrderStatus.hasMany(OrderItemHistory, {
262
+ foreignKey: "OrderStatusID",
263
+ as: "OrderItemStatus",
264
+ });
265
+
266
+ // OrderStatus to Colour
267
+ OrderStatus.belongsTo(Colour, {
268
+ foreignKey: "ColourID",
269
+ as: "Colour",
270
+ });
271
+ //Payment
272
+ Payment.belongsTo(Order, {
273
+ foreignKey: "OrderID",
274
+ as: "Order",
275
+ });
276
+ Payment.belongsTo(PaymentStatus, {
277
+ foreignKey: "PaymentStatusID",
278
+ as: "PaymentStatus",
279
+ });
280
+ Payment.belongsTo(PaymentMethod, {
281
+ foreignKey: "PaymentMethodID",
282
+ as: "PaymentMethod",
283
+ });
284
+ Payment.belongsTo(PaymentType, {
285
+ foreignKey: "PaymentTypeID",
286
+ as: "PaymentType",
287
+ });
288
+
289
+ // Feedback Associations
290
+ Feedback.belongsTo(Product, { foreignKey: "ProductID", as: "Product" });
291
+ Feedback.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
292
+ Feedback.belongsTo(OrderItem, {
293
+ foreignKey: "OrderItemID",
294
+ as: "OrderItem",
295
+ });
296
+
297
+ //
298
+ Product.hasMany(Feedback, { foreignKey: "ProductID", as: "Feedback" });
299
+ Customer.hasMany(Feedback, { foreignKey: "CustomerID", as: "Feedback" });
300
+
301
+ Customer.hasMany(Order, {
302
+ foreignKey: "CustomerID",
303
+ as: "Orders",
304
+ });
305
+
306
+ ProductVariant.hasMany(OrderItem, {
307
+ foreignKey: "ProductVariantID",
308
+ as: "OrderItems",
309
+ });
310
+
311
+ // One-to-Many: AttributeType has many Attributes
312
+ AttributeType.hasMany(AttributeValue, {
313
+ foreignKey: "AttributeTypeID",
314
+ as: "AttributeValue",
315
+ });
316
+
317
+ // Many-to-One: Attribute belongs to an AttributeType
318
+ AttributeValue.belongsTo(AttributeType, {
319
+ foreignKey: "AttributeTypeID",
320
+ as: "AttributeType",
321
+ });
322
+
323
+ // ProductVariant and Inventory association
324
+ ProductVariant.hasMany(Inventory, {
325
+ foreignKey: "ProductVariantID",
326
+ as: "Inventory",
327
+ });
328
+
329
+ Inventory.belongsTo(ProductVariant, {
330
+ foreignKey: "ProductVariantID",
331
+ as: "ProductVariant",
332
+ });
333
+
334
+ // Inventory and Store association
335
+ Inventory.belongsTo(Store, {
336
+ foreignKey: "StoreID",
337
+ as: "Store",
338
+ });
339
+
340
+ ProductSpecification.belongsTo(SpecificationType, {
341
+ foreignKey: "SpecificationTypeID",
342
+ as: "SpecificationType",
343
+ });
344
+
345
+ SpecificationType.hasMany(ProductSpecification, {
346
+ foreignKey: "SpecificationTypeID",
347
+ as: "ProductSpecifications",
348
+ });
349
+
350
+ Product.belongsToMany(SpecificationType, {
351
+ through: ProductSpecification, // join model
352
+ foreignKey: "ProductID",
353
+ otherKey: "SpecificationTypeID",
354
+ as: "SpecificationTypes",
355
+ });
356
+
357
+ SpecificationType.belongsToMany(Product, {
358
+ through: ProductSpecification,
359
+ foreignKey: "SpecificationTypeID",
360
+ otherKey: "ProductID",
361
+ as: "Products",
362
+ });
363
+
364
+ //wishlist association
365
+ WishList.belongsTo(ProductVariant, {
366
+ foreignKey: "ProductVariantID",
367
+ as: "ProductVariant",
368
+ });
369
+
370
+ WishList.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
371
+ ProductVariant.hasMany(WishList, {
372
+ foreignKey: "ProductVariantID",
373
+ as: "WishList",
374
+ });
375
+
376
+ Customer.hasMany(WishList, { foreignKey: "CustomerID", as: "WishList" });
377
+
378
+ // Cart and ProductVariant Association
379
+ Cart.belongsTo(ProductVariant, {
380
+ foreignKey: "ProductVariantID",
381
+ as: "ProductVariant",
382
+ });
383
+
384
+ Cart.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
385
+
386
+ Cart.belongsTo(Inventory, { foreignKey: "InventoryID", as: "Inventory" });
387
+
388
+ // subscription
389
+ // SubscriptionPlan and SubscriptionFeature
390
+ SubscriptionPlan.belongsToMany(SubscriptionFeature, {
391
+ through: SubscriptionPlanFeature,
392
+ foreignKey: "SubscriptionPlanID",
393
+ otherKey: "SubscriptionFeatureID",
394
+ as: "Features",
395
+ });
396
+
397
+ SubscriptionFeature.belongsToMany(SubscriptionPlan, {
398
+ through: SubscriptionPlanFeature,
399
+ foreignKey: "SubscriptionFeatureID",
400
+ otherKey: "SubscriptionPlanID",
401
+ as: "SubscriptionPlans",
402
+ });
403
+
404
+ // SubscriptionPlan and Tenant
405
+ Tenant.hasOne(TenantSubscription, {
406
+ foreignKey: "TenantID",
407
+ as: "CurrentSubscription",
408
+ });
409
+
410
+ TenantSubscription.belongsTo(models.Tenant, {
411
+ foreignKey: "TenantID",
412
+ as: "SubscribedTenant",
413
+ });
414
+
415
+ TenantSubscription.belongsTo(models.SubscriptionPlan, {
416
+ foreignKey: "SubscriptionPlanID",
417
+ as: "SubscriptionPlan",
418
+ });
419
+
420
+ // ProductImport and ProductImportFailureAudits
421
+ ProductImport.hasMany(ProductImportFailureAudits, {
422
+ foreignKey: 'ProductImportID',
423
+ as: "ProductImportFailureAudits",
424
+ });
425
+
426
+ ProductImportFailureAudits.belongsTo(ProductImport, {
427
+ foreignKey: 'ProductImportID',
428
+ as: 'ProductImport'
429
+ })
430
+ return { ...models };
431
+ };
432
+ module.exports = initializeModels;