@b2y/ecommerce-common 1.3.6 → 1.3.8

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