@b2y/ecommerce-common 1.0.5 → 1.0.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 (68) 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 +383 -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 +29 -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/PdfUtil.js +64 -0
  66. package/utility/QueryUtil.js +261 -261
  67. package/utility/Razorpay.js +65 -65
  68. package/utility/VariantPriceUtil.js +54 -54
@@ -1,380 +1,384 @@
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 Order
101
+ Order.belongsTo(Tenant, { foreignKey: 'TenantID', as: 'Tenant' });
102
+ Tenant.hasMany(Order, { foreignKey: 'TenantID', as: 'Order' });
103
+
104
+ // Tenant and Customer (One-to-many: A Tenant has many Customers)
105
+ Tenant.hasMany(Customer, { foreignKey: "TenantID", as: "Customer" });
106
+ Customer.belongsTo(Tenant, { foreignKey: "TenantID", as: "Tenant" });
107
+
108
+ Address.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
109
+ Customer.hasMany(Address, { foreignKey: "CustomerID", as: "Address" });
110
+
111
+
112
+ /*---- product related associations -----*/
113
+ // Product and ProductVariant Associations
114
+ // One-to-Many
115
+ Product.hasMany(ProductVariant, {
116
+ foreignKey: "ProductID",
117
+ as: "ProductVariant",
118
+ });
119
+ ProductVariant.belongsTo(Product, {
120
+ foreignKey: "ProductID",
121
+ as: "Product",
122
+ });
123
+
124
+ // Product and Category Association
125
+ // Many-to-One
126
+ Product.belongsTo(Category, { foreignKey: "CategoryID", as: "Category" });
127
+ Category.hasMany(Product, { foreignKey: "CategoryID", as: "Product" });
128
+
129
+ // Product and Brand Association
130
+ // Many-to-One
131
+ Product.belongsTo(Brand, { foreignKey: "BrandID", as: "Brand" });
132
+
133
+ // Brand model definition
134
+ Brand.hasMany(Product, {
135
+ foreignKey: "BrandID", // Make sure the foreign key matches in both models
136
+ as: "Product",
137
+ });
138
+
139
+ // ProductVariant and ProductVariantAttribute
140
+ ProductVariant.belongsToMany(AttributeValue, {
141
+ through: ProductVariantAttribute,
142
+ foreignKey: "ProductVariantID",
143
+ otherKey: "AttributeValueID",
144
+ as: "AttributeValues",
145
+ });
146
+
147
+ AttributeValue.belongsToMany(ProductVariant, {
148
+ through: ProductVariantAttribute,
149
+ foreignKey: "AttributeValueID",
150
+ otherKey: "ProductVariantID",
151
+ as: "ProductVariants",
152
+ });
153
+
154
+ ProductVariant.hasMany(ProductVariantAttribute, {
155
+ foreignKey: "ProductVariantID",
156
+ as: "VariantAttributes",
157
+ });
158
+ ProductVariantAttribute.belongsTo(ProductVariant, {
159
+ foreignKey: "ProductVariantID",
160
+ as: "Variant",
161
+ });
162
+
163
+ // AttributeValue and ProductVariantAttribute
164
+ AttributeValue.hasMany(ProductVariantAttribute, {
165
+ foreignKey: "AttributeValueID",
166
+ as: "VariantAttributes",
167
+ });
168
+ ProductVariantAttribute.belongsTo(AttributeValue, {
169
+ foreignKey: "AttributeValueID",
170
+ as: "AttributeValue",
171
+ });
172
+
173
+ // Product and ProductGroup Association
174
+ // Many-to-One
175
+ Product.belongsTo(ProductGroup, {
176
+ foreignKey: "ProductGroupID",
177
+ as: "ProductGroup",
178
+ });
179
+ ProductGroup.hasMany(Product, {
180
+ foreignKey: "ProductGroupID",
181
+ as: "Product",
182
+ });
183
+
184
+ // Order
185
+ Order.belongsTo(Customer, {
186
+ foreignKey: "CustomerID",
187
+ as: "Customer",
188
+ });
189
+
190
+ Order.belongsTo(Address, {
191
+ foreignKey: "AddressID",
192
+ as: "Address",
193
+ });
194
+
195
+ Order.hasMany(OrderItem, {
196
+ foreignKey: "OrderID",
197
+ as: "OrderItem",
198
+ });
199
+ Order.hasMany(Payment, {
200
+ foreignKey: "OrderID",
201
+ as: "Payment",
202
+ });
203
+
204
+ // OrderItem
205
+ OrderItem.belongsTo(Order, {
206
+ foreignKey: "OrderID",
207
+ as: "Order",
208
+ });
209
+
210
+ OrderItem.belongsTo(ProductVariant, {
211
+ foreignKey: "ProductVariantID",
212
+ as: "ProductVariant",
213
+ });
214
+
215
+ // OrderItem to Store association
216
+ OrderItem.belongsTo(Store, {
217
+ foreignKey: "StoreID",
218
+ as: "Store",
219
+ });
220
+
221
+ Store.hasMany(OrderItem, {
222
+ foreignKey: "StoreID",
223
+ as: "OrderItem",
224
+ });
225
+
226
+ OrderItem.belongsTo(OrderStatus, {
227
+ foreignKey: "OrderStatusID",
228
+ as: "OrderItemStatus",
229
+ });
230
+ OrderStatus.hasMany(OrderItem, {
231
+ foreignKey: "OrderStatusID",
232
+ as: "OrderItem",
233
+ });
234
+ // OrderItem to OrderItemHistory association
235
+ OrderItem.hasMany(OrderItemHistory, {
236
+ foreignKey: "OrderItemID",
237
+ as: "OrderItemHistory",
238
+ });
239
+
240
+ // OrderItem to Feedback
241
+ OrderItem.hasMany(Feedback, {
242
+ foreignKey: "OrderItemID",
243
+ as: "Feedback",
244
+ });
245
+ OrderItemHistory.belongsTo(OrderItem, {
246
+ foreignKey: "OrderItemID",
247
+ as: "OrderItem",
248
+ });
249
+
250
+ // OrderItemHistory to OrderStatus association
251
+ OrderItemHistory.belongsTo(OrderStatus, {
252
+ foreignKey: "OrderStatusID",
253
+ as: "OrderItemStatus",
254
+ });
255
+ OrderStatus.hasMany(OrderItemHistory, {
256
+ foreignKey: "OrderStatusID",
257
+ as: "OrderItemStatus",
258
+ });
259
+
260
+ // OrderStatus to Colour
261
+ OrderStatus.belongsTo(Colour, {
262
+ foreignKey: "ColourID",
263
+ as: "Colour",
264
+ });
265
+ //Payment
266
+ Payment.belongsTo(Order, {
267
+ foreignKey: "OrderID",
268
+ as: "Order",
269
+ });
270
+ Payment.belongsTo(PaymentStatus, {
271
+ foreignKey: "PaymentStatusID",
272
+ as: "PaymentStatus",
273
+ });
274
+ Payment.belongsTo(PaymentMethod, {
275
+ foreignKey: "PaymentMethodID",
276
+ as: "PaymentMethod",
277
+ });
278
+ Payment.belongsTo(PaymentType, {
279
+ foreignKey: "PaymentTypeID",
280
+ as: "PaymentType",
281
+ });
282
+
283
+ // Feedback Associations
284
+ Feedback.belongsTo(Product, { foreignKey: "ProductID", as: "Product" });
285
+ Feedback.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
286
+ Feedback.belongsTo(OrderItem, {
287
+ foreignKey: "OrderItemID",
288
+ as: "OrderItem",
289
+ });
290
+
291
+ //
292
+ Product.hasMany(Feedback, { foreignKey: "ProductID", as: "Feedback" });
293
+ Customer.hasMany(Feedback, { foreignKey: "CustomerID", as: "Feedback" });
294
+
295
+ Customer.hasMany(Order, {
296
+ foreignKey: "CustomerID",
297
+ as: "Orders",
298
+ });
299
+
300
+ ProductVariant.hasMany(OrderItem, {
301
+ foreignKey: "ProductVariantID",
302
+ as: "OrderItems",
303
+ });
304
+
305
+ // One-to-Many: AttributeType has many Attributes
306
+ AttributeType.hasMany(AttributeValue, {
307
+ foreignKey: "AttributeTypeID",
308
+ as: "AttributeValue",
309
+ });
310
+
311
+ // Many-to-One: Attribute belongs to an AttributeType
312
+ AttributeValue.belongsTo(AttributeType, {
313
+ foreignKey: "AttributeTypeID",
314
+ as: "AttributeType",
315
+ });
316
+
317
+ // ProductVariant and Inventory association
318
+ ProductVariant.hasMany(Inventory, {
319
+ foreignKey: "ProductVariantID",
320
+ as: "Inventory",
321
+ });
322
+
323
+ Inventory.belongsTo(ProductVariant, {
324
+ foreignKey: "ProductVariantID",
325
+ as: "ProductVariant",
326
+ });
327
+
328
+ // Inventory and Store association
329
+ Inventory.belongsTo(Store, {
330
+ foreignKey: "StoreID",
331
+ as: "Store",
332
+ });
333
+
334
+ ProductSpecification.belongsTo(SpecificationType, {
335
+ foreignKey: "SpecificationTypeID",
336
+ as: "SpecificationType",
337
+ });
338
+
339
+ SpecificationType.hasMany(ProductSpecification, {
340
+ foreignKey: "SpecificationTypeID",
341
+ as: "ProductSpecifications",
342
+ });
343
+
344
+ Product.belongsToMany(SpecificationType, {
345
+ through: ProductSpecification, // join model
346
+ foreignKey: "ProductID",
347
+ otherKey: "SpecificationTypeID",
348
+ as: "SpecificationTypes",
349
+ });
350
+
351
+ SpecificationType.belongsToMany(Product, {
352
+ through: ProductSpecification,
353
+ foreignKey: "SpecificationTypeID",
354
+ otherKey: "ProductID",
355
+ as: "Products",
356
+ });
357
+
358
+ //wishlist association
359
+ WishList.belongsTo(ProductVariant, {
360
+ foreignKey: "ProductVariantID",
361
+ as: "ProductVariant",
362
+ });
363
+
364
+ WishList.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
365
+ ProductVariant.hasMany(WishList, {
366
+ foreignKey: "ProductVariantID",
367
+ as: "WishList",
368
+ });
369
+
370
+ Customer.hasMany(WishList, { foreignKey: "CustomerID", as: "WishList" });
371
+
372
+ // Cart and ProductVariant Association
373
+ Cart.belongsTo(ProductVariant, {
374
+ foreignKey: "ProductVariantID",
375
+ as: "ProductVariant",
376
+ });
377
+
378
+ Cart.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
379
+
380
+ Cart.belongsTo(Inventory, { foreignKey: "InventoryID", as: "Inventory" });
381
+
382
+ return { ...models };
383
+ };
380
384
  module.exports = initializeModels;