@b2y/ecommerce-common 1.1.1 → 1.1.4

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