@b2y/ecommerce-common 1.0.9 → 1.1.1

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 (77) 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 +420 -420
  6. package/enum/AccessModeEnum.js +7 -6
  7. package/enum/AddressTypeEnum.js +6 -6
  8. package/enum/BillingCycleEnum.js +6 -0
  9. package/enum/BooleanEnum.js +4 -4
  10. package/enum/EntityTypeEnum.js +11 -11
  11. package/enum/FeatureTypeEnum.js +7 -0
  12. package/enum/GenderEnum.js +7 -7
  13. package/enum/NotificationStatusEnum.js +5 -5
  14. package/enum/NotificationTypeEnum.js +9 -9
  15. package/enum/OrderStatusEnum.js +7 -7
  16. package/enum/PaymentMethodEnum.js +6 -6
  17. package/enum/PaymentStatusEnum.js +6 -6
  18. package/enum/PaymentTypeEnum.js +6 -6
  19. package/enum/PlatformEnum.js +4 -4
  20. package/enum/RegistrationStatusEnum.js +5 -5
  21. package/enum/SortByEnum.js +7 -7
  22. package/enum/SubscriptionStatusEnum.js +7 -7
  23. package/index.js +22 -22
  24. package/model/Address.js +95 -95
  25. package/model/AttributeType.js +50 -50
  26. package/model/AttributeValue.js +64 -64
  27. package/model/Banner.js +78 -78
  28. package/model/Brand.js +76 -76
  29. package/model/Cart.js +76 -76
  30. package/model/Category.js +72 -72
  31. package/model/CategoryAttributeType.js +62 -62
  32. package/model/Colour.js +52 -52
  33. package/model/Customer.js +94 -94
  34. package/model/DeviceToken.js +51 -51
  35. package/model/Document.js +70 -70
  36. package/model/DynamicUIComponent.js +52 -52
  37. package/model/Feedback.js +79 -79
  38. package/model/Inventory.js +83 -83
  39. package/model/NotificationHistory.js +67 -67
  40. package/model/Order.js +94 -94
  41. package/model/OrderItem.js +98 -98
  42. package/model/OrderItemHistory.js +69 -69
  43. package/model/OrderStatus.js +48 -48
  44. package/model/Payment.js +101 -101
  45. package/model/PaymentMethod.js +36 -36
  46. package/model/PaymentStatus.js +36 -36
  47. package/model/PaymentType.js +36 -36
  48. package/model/Permission.js +55 -55
  49. package/model/Product.js +82 -82
  50. package/model/ProductGroup.js +48 -48
  51. package/model/ProductSpecification.js +65 -65
  52. package/model/ProductVariant.js +75 -75
  53. package/model/ProductVariantAttribute.js +58 -58
  54. package/model/Role.js +61 -61
  55. package/model/RolePermissionMapping.js +63 -63
  56. package/model/SpecificationType.js +41 -41
  57. package/model/Store.js +99 -99
  58. package/model/StoreUserMapping.js +44 -44
  59. package/model/SubscriptionFeature.js +49 -49
  60. package/model/SubscriptionPlan.js +66 -61
  61. package/model/SubscriptionPlanFeature.js +48 -48
  62. package/model/Tenant.js +91 -91
  63. package/model/TenantSettings.js +47 -47
  64. package/model/TenantSubscription.js +73 -67
  65. package/model/User.js +132 -132
  66. package/model/WishList.js +62 -62
  67. package/package.json +29 -29
  68. package/utility/AppUtil.js +65 -65
  69. package/utility/DateUtil.js +55 -55
  70. package/utility/ExcelUtil.js +125 -125
  71. package/utility/LocationUtility.js +130 -130
  72. package/utility/OrderTimeFilterUtil.js +88 -88
  73. package/utility/PdfUtil.js +64 -63
  74. package/utility/QueryUtil.js +261 -261
  75. package/utility/Razorpay.js +65 -65
  76. package/utility/ResolveAccessMode.js +38 -24
  77. package/utility/VariantPriceUtil.js +54 -54
@@ -1,420 +1,420 @@
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
+ } = 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;