@b2y/ecommerce-common 1.0.5 → 1.0.6

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