@b2y/ecommerce-common 1.0.0
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.
- package/README.md +4 -0
- package/constants/AppConstants.js +4 -0
- package/constants/ReportConstants.js +15 -0
- package/constants/StatusMessageConstants.js +21 -0
- package/dbconnection/Connect.js +417 -0
- package/enum/AddressTypeEnum.js +7 -0
- package/enum/BooleanEnum.js +5 -0
- package/enum/EntityTypeEnum.js +10 -0
- package/enum/GenderEnum.js +7 -0
- package/enum/NotificationStatusEnum.js +6 -0
- package/enum/NotificationTypeEnum.js +10 -0
- package/enum/OrderStatusEnum.js +8 -0
- package/enum/PaymentMethodEnum.js +7 -0
- package/enum/PaymentStatusEnum.js +7 -0
- package/enum/PaymentTypeEnum.js +7 -0
- package/enum/PlatformEnum.js +5 -0
- package/enum/RegistrationStatusEnum.js +6 -0
- package/enum/SortByEnum.js +8 -0
- package/index.js +22 -0
- package/model/Address.js +114 -0
- package/model/AttributeType.js +51 -0
- package/model/AttributeValue.js +65 -0
- package/model/Banner.js +79 -0
- package/model/Brand.js +76 -0
- package/model/Cart.js +77 -0
- package/model/Category.js +73 -0
- package/model/CategoryAttributeType.js +63 -0
- package/model/City.js +49 -0
- package/model/Colour.js +53 -0
- package/model/Country.js +47 -0
- package/model/Customer.js +95 -0
- package/model/DeviceToken.js +52 -0
- package/model/Document.js +71 -0
- package/model/DynamicUIComponent.js +53 -0
- package/model/Feedback.js +80 -0
- package/model/Inventory.js +84 -0
- package/model/NotificationHistory.js +68 -0
- package/model/Order.js +95 -0
- package/model/OrderItem.js +99 -0
- package/model/OrderItemHistory.js +70 -0
- package/model/OrderStatus.js +49 -0
- package/model/Payment.js +101 -0
- package/model/PaymentMethod.js +37 -0
- package/model/PaymentStatus.js +37 -0
- package/model/PaymentType.js +37 -0
- package/model/Permission.js +55 -0
- package/model/Product.js +83 -0
- package/model/ProductGroup.js +48 -0
- package/model/ProductSpecification.js +66 -0
- package/model/ProductVariant.js +76 -0
- package/model/ProductVariantAttribute.js +59 -0
- package/model/Role.js +61 -0
- package/model/RolePermissionMapping.js +63 -0
- package/model/SpecificationType.js +42 -0
- package/model/State.js +56 -0
- package/model/Store.js +117 -0
- package/model/StoreUserMapping.js +44 -0
- package/model/Tenant.js +91 -0
- package/model/User.js +150 -0
- package/model/WishList.js +63 -0
- package/package.json +27 -0
- package/utility/AppUtil.js +58 -0
- package/utility/DateUtil.js +55 -0
- package/utility/ExcelUtil.js +125 -0
- package/utility/OrderTimeFilterUtil.js +86 -0
- package/utility/QueryUtil.js +262 -0
- package/utility/Razorpay.js +67 -0
- package/utility/VariantPriceUtil.js +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# ecommerce-common
|
|
2
|
+
E-commerce common library
|
|
3
|
+
A reusable, modular **common package** containing shared models, utilities, enums, helpers, and base configurations for the E-Commerce platform.
|
|
4
|
+
This package centralizes ecommerce-Admin and ecommerce-customer cross-project logic so multiple services can stay consistent and maintainable.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
const EXCEL_METADATA = {
|
|
3
|
+
CREATOR: "Ecommerce System", // this can be customized as per requirement
|
|
4
|
+
LAST_MODIFIED_BY: "Ecommerce System"
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const EXCEL_DEFAULT_THEME = {
|
|
8
|
+
HEADER_FILL_COLOR: "1E90FF", // default header color
|
|
9
|
+
HEADER_FONT_COLOR: "FFFFFFFF"
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
EXCEL_METADATA,
|
|
14
|
+
EXCEL_DEFAULT_THEME
|
|
15
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const StatusMessageConstants = {
|
|
2
|
+
PRODUCTVARIANT_INVALID_MRP: 'Invalid MRP: must be positive',
|
|
3
|
+
PRODUCTVARIANT_MISSING_PRICE_OR_DISCOUNT: 'Either SellingPrice or DiscountPercentage must be provided',
|
|
4
|
+
PRODUCTVARIANT_INCONSISTENT_PRICING: 'Inconsistent pricing: provided discount percentage does not match calculated value',
|
|
5
|
+
PRODUCTVARIANT_SELLING_PRICE_EXCEEDS_MRP: 'SellingPrice cannot exceed MRP',
|
|
6
|
+
PRODUCTVARIANT_INVALID_SELLING_PRICE: 'SellingPrice cannot be negative',
|
|
7
|
+
PRODUCTVARIANT_INVALID_DISCOUNT_PERCENTAGE: 'DiscountPercentage must be between 0 and 100',
|
|
8
|
+
INVALID_DATE_FORMAT: "Invalid date format",
|
|
9
|
+
INVALID_DATE_RANGE: "StartDate cannot be after EndDate",
|
|
10
|
+
DATE_RANGE_REQUIRED: "Both startDate and endDate must be provided together",
|
|
11
|
+
INVALID_END_DATE: "Invalid endDate",
|
|
12
|
+
INVALID_START_DATE: "Invalid startDate",
|
|
13
|
+
INVALID_ISACTIVE_STATUS: "IsActive must be either true or false",
|
|
14
|
+
PAYMENT_STATUS_INVALID: "PaymentStatus is invalid",
|
|
15
|
+
PAYMENT_TYPE_INVALID: "PaymentType is invalid",
|
|
16
|
+
PAYMENT_METHOD_INVALID: "PaymentMethod is invalid",
|
|
17
|
+
ORDER_CREATION_FAILED:"Order creation failed",
|
|
18
|
+
PAYMENT_SIGNATURE_VERIFICATION_FAILED:"Payment signature verification failed",
|
|
19
|
+
PAYMENT_VERIFICATION_FAILED:"Payment verification failed"
|
|
20
|
+
}
|
|
21
|
+
module.exports = StatusMessageConstants;
|
|
@@ -0,0 +1,417 @@
|
|
|
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
|
+
User,
|
|
13
|
+
Customer,
|
|
14
|
+
Address,
|
|
15
|
+
City,
|
|
16
|
+
State,
|
|
17
|
+
Country,
|
|
18
|
+
Product,
|
|
19
|
+
ProductVariant,
|
|
20
|
+
Category,
|
|
21
|
+
Brand,
|
|
22
|
+
Colour,
|
|
23
|
+
Order,
|
|
24
|
+
OrderItem,
|
|
25
|
+
Payment,
|
|
26
|
+
PaymentStatus,
|
|
27
|
+
PaymentMethod,
|
|
28
|
+
PaymentType,
|
|
29
|
+
Feedback,
|
|
30
|
+
Role,
|
|
31
|
+
Permission,
|
|
32
|
+
RolePermissionMapping,
|
|
33
|
+
DeviceToken,
|
|
34
|
+
NotificationHistory,
|
|
35
|
+
DynamicUIComponent,
|
|
36
|
+
ProductGroup,
|
|
37
|
+
OrderStatus,
|
|
38
|
+
Banner,
|
|
39
|
+
Document,
|
|
40
|
+
AttributeType,
|
|
41
|
+
AttributeValue,
|
|
42
|
+
Store,
|
|
43
|
+
StoreUserMapping,
|
|
44
|
+
OrderItemHistory,
|
|
45
|
+
Inventory,
|
|
46
|
+
SpecificationType,
|
|
47
|
+
ProductSpecification,
|
|
48
|
+
ProductVariantAttribute,
|
|
49
|
+
Cart,
|
|
50
|
+
WishList,
|
|
51
|
+
} = models;
|
|
52
|
+
Category.hasMany(Category, {
|
|
53
|
+
foreignKey: "ParentCategoryID",
|
|
54
|
+
as: "subCategories",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
Category.belongsTo(Category, {
|
|
58
|
+
foreignKey: "ParentCategoryID",
|
|
59
|
+
as: "parentCategory",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
User.belongsTo(City, {
|
|
63
|
+
foreignKey: "CityID",
|
|
64
|
+
as: "City", // Alias for the association
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// User associations
|
|
68
|
+
User.belongsTo(State, {
|
|
69
|
+
foreignKey: "StateID",
|
|
70
|
+
as: "State", // Alias for the association
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
User.belongsTo(Country, {
|
|
74
|
+
foreignKey: "CountryID",
|
|
75
|
+
as: "Country", // Alias for the association
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// In Store model
|
|
79
|
+
Store.belongsTo(City, { foreignKey: "CityID", as: "City" });
|
|
80
|
+
|
|
81
|
+
// In Store model
|
|
82
|
+
Store.belongsTo(State, { foreignKey: "StateID", as: "State" });
|
|
83
|
+
|
|
84
|
+
// Store.js
|
|
85
|
+
Store.belongsTo(Country, { foreignKey: "CountryID", as: "Country" });
|
|
86
|
+
|
|
87
|
+
Store.belongsToMany(User, {
|
|
88
|
+
through: StoreUserMapping,
|
|
89
|
+
foreignKey: "StoreID",
|
|
90
|
+
otherKey: "UserID",
|
|
91
|
+
as: "User",
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
User.belongsToMany(Store, {
|
|
95
|
+
through: StoreUserMapping,
|
|
96
|
+
foreignKey: "UserID",
|
|
97
|
+
otherKey: "StoreID",
|
|
98
|
+
as: "Store",
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
//permissions
|
|
102
|
+
// Role to Permission (many-to-many through RolePermissionMapping)
|
|
103
|
+
Role.belongsToMany(Permission, {
|
|
104
|
+
through: RolePermissionMapping,
|
|
105
|
+
foreignKey: "RoleID",
|
|
106
|
+
otherKey: "PermissionID",
|
|
107
|
+
as: "Permission",
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
Permission.belongsToMany(Role, {
|
|
111
|
+
through: RolePermissionMapping,
|
|
112
|
+
foreignKey: "PermissionID",
|
|
113
|
+
otherKey: "RoleID",
|
|
114
|
+
as: "Role",
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// User to Roles association
|
|
118
|
+
User.belongsTo(Role, { foreignKey: "RoleID", as: "UserRole" });
|
|
119
|
+
Role.hasMany(User, { foreignKey: "RoleID" });
|
|
120
|
+
|
|
121
|
+
/*---- users realted associations ----*/
|
|
122
|
+
// Tenant and UserManagement (One-to-many: A Tenant has many UserManagement entries)
|
|
123
|
+
Tenant.hasMany(User, { foreignKey: "TenantID", as: "User" });
|
|
124
|
+
User.belongsTo(Tenant, { foreignKey: "TenantID", as: "Tenant" });
|
|
125
|
+
|
|
126
|
+
// Tenant and Customer (One-to-many: A Tenant has many Customers)
|
|
127
|
+
Tenant.hasMany(Customer, { foreignKey: "TenantID", as: "Customer" });
|
|
128
|
+
Customer.belongsTo(Tenant, { foreignKey: "TenantID", as: "Tenant" });
|
|
129
|
+
|
|
130
|
+
Address.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
|
|
131
|
+
Customer.hasMany(Address, { foreignKey: "CustomerID", as: "Address" });
|
|
132
|
+
|
|
133
|
+
// Address belongs to City
|
|
134
|
+
Address.belongsTo(City, { foreignKey: "CityID", as: "City" });
|
|
135
|
+
City.hasMany(Address, { foreignKey: "CityID", as: "Address" });
|
|
136
|
+
|
|
137
|
+
// Address belongs to State
|
|
138
|
+
Address.belongsTo(State, { foreignKey: "StateID", as: "State" });
|
|
139
|
+
State.hasMany(Address, { foreignKey: "StateID", as: "Address" });
|
|
140
|
+
|
|
141
|
+
// Address belongs to Country
|
|
142
|
+
Address.belongsTo(Country, { foreignKey: "CountryID", as: "Country" });
|
|
143
|
+
Country.hasMany(Address, { foreignKey: "CountryID", as: "Address" });
|
|
144
|
+
|
|
145
|
+
/*---- product related associations -----*/
|
|
146
|
+
// Product and ProductVariant Associations
|
|
147
|
+
// One-to-Many
|
|
148
|
+
Product.hasMany(ProductVariant, {
|
|
149
|
+
foreignKey: "ProductID",
|
|
150
|
+
as: "ProductVariant",
|
|
151
|
+
});
|
|
152
|
+
ProductVariant.belongsTo(Product, {
|
|
153
|
+
foreignKey: "ProductID",
|
|
154
|
+
as: "Product",
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Product and Category Association
|
|
158
|
+
// Many-to-One
|
|
159
|
+
Product.belongsTo(Category, { foreignKey: "CategoryID", as: "Category" });
|
|
160
|
+
Category.hasMany(Product, { foreignKey: "CategoryID", as: "Product" });
|
|
161
|
+
|
|
162
|
+
// Product and Brand Association
|
|
163
|
+
// Many-to-One
|
|
164
|
+
Product.belongsTo(Brand, { foreignKey: "BrandID", as: "Brand" });
|
|
165
|
+
|
|
166
|
+
// Brand model definition
|
|
167
|
+
Brand.hasMany(Product, {
|
|
168
|
+
foreignKey: "BrandID", // Make sure the foreign key matches in both models
|
|
169
|
+
as: "Product",
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// ProductVariant and ProductVariantAttribute
|
|
173
|
+
ProductVariant.belongsToMany(AttributeValue, {
|
|
174
|
+
through: ProductVariantAttribute,
|
|
175
|
+
foreignKey: "ProductVariantID",
|
|
176
|
+
otherKey: "AttributeValueID",
|
|
177
|
+
as: "AttributeValues",
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
AttributeValue.belongsToMany(ProductVariant, {
|
|
181
|
+
through: ProductVariantAttribute,
|
|
182
|
+
foreignKey: "AttributeValueID",
|
|
183
|
+
otherKey: "ProductVariantID",
|
|
184
|
+
as: "ProductVariants",
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
ProductVariant.hasMany(ProductVariantAttribute, {
|
|
188
|
+
foreignKey: "ProductVariantID",
|
|
189
|
+
as: "VariantAttributes",
|
|
190
|
+
});
|
|
191
|
+
ProductVariantAttribute.belongsTo(ProductVariant, {
|
|
192
|
+
foreignKey: "ProductVariantID",
|
|
193
|
+
as: "Variant",
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// AttributeValue and ProductVariantAttribute
|
|
197
|
+
AttributeValue.hasMany(ProductVariantAttribute, {
|
|
198
|
+
foreignKey: "AttributeValueID",
|
|
199
|
+
as: "VariantAttributes",
|
|
200
|
+
});
|
|
201
|
+
ProductVariantAttribute.belongsTo(AttributeValue, {
|
|
202
|
+
foreignKey: "AttributeValueID",
|
|
203
|
+
as: "AttributeValue",
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Product and ProductGroup Association
|
|
207
|
+
// Many-to-One
|
|
208
|
+
Product.belongsTo(ProductGroup, {
|
|
209
|
+
foreignKey: "ProductGroupID",
|
|
210
|
+
as: "ProductGroup",
|
|
211
|
+
});
|
|
212
|
+
ProductGroup.hasMany(Product, {
|
|
213
|
+
foreignKey: "ProductGroupID",
|
|
214
|
+
as: "Product",
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Order
|
|
218
|
+
Order.belongsTo(Customer, {
|
|
219
|
+
foreignKey: "CustomerID",
|
|
220
|
+
as: "Customer",
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
Order.belongsTo(Address, {
|
|
224
|
+
foreignKey: "AddressID",
|
|
225
|
+
as: "Address",
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
Order.hasMany(OrderItem, {
|
|
229
|
+
foreignKey: "OrderID",
|
|
230
|
+
as: "OrderItem",
|
|
231
|
+
});
|
|
232
|
+
Order.hasMany(Payment, {
|
|
233
|
+
foreignKey: "OrderID",
|
|
234
|
+
as: "Payment",
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// OrderItem
|
|
238
|
+
OrderItem.belongsTo(Order, {
|
|
239
|
+
foreignKey: "OrderID",
|
|
240
|
+
as: "Order",
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
OrderItem.belongsTo(ProductVariant, {
|
|
244
|
+
foreignKey: "ProductVariantID",
|
|
245
|
+
as: "ProductVariant",
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// OrderItem to Store association
|
|
249
|
+
OrderItem.belongsTo(Store, {
|
|
250
|
+
foreignKey: "StoreID",
|
|
251
|
+
as: "Store",
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
Store.hasMany(OrderItem, {
|
|
255
|
+
foreignKey: "StoreID",
|
|
256
|
+
as: "OrderItem",
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
OrderItem.belongsTo(OrderStatus, {
|
|
260
|
+
foreignKey: "OrderStatusID",
|
|
261
|
+
as: "OrderItemStatus",
|
|
262
|
+
});
|
|
263
|
+
OrderStatus.hasMany(OrderItem, {
|
|
264
|
+
foreignKey: "OrderStatusID",
|
|
265
|
+
as: "OrderItem",
|
|
266
|
+
});
|
|
267
|
+
// OrderItem to OrderItemHistory association
|
|
268
|
+
OrderItem.hasMany(OrderItemHistory, {
|
|
269
|
+
foreignKey: "OrderItemID",
|
|
270
|
+
as: "OrderItemHistory",
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// OrderItem to Feedback
|
|
274
|
+
OrderItem.hasMany(Feedback, {
|
|
275
|
+
foreignKey: "OrderItemID",
|
|
276
|
+
as: "Feedback",
|
|
277
|
+
});
|
|
278
|
+
OrderItemHistory.belongsTo(OrderItem, {
|
|
279
|
+
foreignKey: "OrderItemID",
|
|
280
|
+
as: "OrderItem",
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// OrderItemHistory to OrderStatus association
|
|
284
|
+
OrderItemHistory.belongsTo(OrderStatus, {
|
|
285
|
+
foreignKey: "OrderStatusID",
|
|
286
|
+
as: "OrderItemStatus",
|
|
287
|
+
});
|
|
288
|
+
OrderStatus.hasMany(OrderItemHistory, {
|
|
289
|
+
foreignKey: "OrderStatusID",
|
|
290
|
+
as: "OrderItemStatus",
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// OrderStatus to Colour
|
|
294
|
+
OrderStatus.belongsTo(Colour, {
|
|
295
|
+
foreignKey: "ColourID",
|
|
296
|
+
as: "Colour",
|
|
297
|
+
});
|
|
298
|
+
//Payment
|
|
299
|
+
Payment.belongsTo(Order, {
|
|
300
|
+
foreignKey: "OrderID",
|
|
301
|
+
as: "Order",
|
|
302
|
+
});
|
|
303
|
+
Payment.belongsTo(PaymentStatus, {
|
|
304
|
+
foreignKey: "PaymentStatusID",
|
|
305
|
+
as: "PaymentStatus",
|
|
306
|
+
});
|
|
307
|
+
Payment.belongsTo(PaymentMethod, {
|
|
308
|
+
foreignKey: "PaymentMethodID",
|
|
309
|
+
as: "PaymentMethod",
|
|
310
|
+
});
|
|
311
|
+
Payment.belongsTo(PaymentType, {
|
|
312
|
+
foreignKey: "PaymentTypeID",
|
|
313
|
+
as: "PaymentType",
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Feedback Associations
|
|
317
|
+
Feedback.belongsTo(Product, { foreignKey: "ProductID", as: "Product" });
|
|
318
|
+
Feedback.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
|
|
319
|
+
Feedback.belongsTo(OrderItem, {
|
|
320
|
+
foreignKey: "OrderItemID",
|
|
321
|
+
as: "OrderItem",
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
//
|
|
325
|
+
Product.hasMany(Feedback, { foreignKey: "ProductID", as: "Feedback" });
|
|
326
|
+
Customer.hasMany(Feedback, { foreignKey: "CustomerID", as: "Feedback" });
|
|
327
|
+
|
|
328
|
+
Customer.hasMany(Order, {
|
|
329
|
+
foreignKey: "CustomerID",
|
|
330
|
+
as: "Orders",
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
ProductVariant.hasMany(OrderItem, {
|
|
334
|
+
foreignKey: "ProductVariantID",
|
|
335
|
+
as: "OrderItems",
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// One-to-Many: AttributeType has many Attributes
|
|
339
|
+
AttributeType.hasMany(AttributeValue, {
|
|
340
|
+
foreignKey: "AttributeTypeID",
|
|
341
|
+
as: "AttributeValue",
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// Many-to-One: Attribute belongs to an AttributeType
|
|
345
|
+
AttributeValue.belongsTo(AttributeType, {
|
|
346
|
+
foreignKey: "AttributeTypeID",
|
|
347
|
+
as: "AttributeType",
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// ProductVariant and Inventory association
|
|
351
|
+
ProductVariant.hasMany(Inventory, {
|
|
352
|
+
foreignKey: "ProductVariantID",
|
|
353
|
+
as: "Inventory",
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
Inventory.belongsTo(ProductVariant, {
|
|
357
|
+
foreignKey: "ProductVariantID",
|
|
358
|
+
as: "ProductVariant",
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// Inventory and Store association
|
|
362
|
+
Inventory.belongsTo(Store, {
|
|
363
|
+
foreignKey: "StoreID",
|
|
364
|
+
as: "Store",
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
ProductSpecification.belongsTo(SpecificationType, {
|
|
368
|
+
foreignKey: "SpecificationTypeID",
|
|
369
|
+
as: "SpecificationType",
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
SpecificationType.hasMany(ProductSpecification, {
|
|
373
|
+
foreignKey: "SpecificationTypeID",
|
|
374
|
+
as: "ProductSpecifications",
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
Product.belongsToMany(SpecificationType, {
|
|
378
|
+
through: ProductSpecification, // join model
|
|
379
|
+
foreignKey: "ProductID",
|
|
380
|
+
otherKey: "SpecificationTypeID",
|
|
381
|
+
as: "SpecificationTypes",
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
SpecificationType.belongsToMany(Product, {
|
|
385
|
+
through: ProductSpecification,
|
|
386
|
+
foreignKey: "SpecificationTypeID",
|
|
387
|
+
otherKey: "ProductID",
|
|
388
|
+
as: "Products",
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
//wishlist association
|
|
392
|
+
WishList.belongsTo(ProductVariant, {
|
|
393
|
+
foreignKey: "ProductVariantID",
|
|
394
|
+
as: "ProductVariant",
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
WishList.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
|
|
398
|
+
ProductVariant.hasMany(WishList, {
|
|
399
|
+
foreignKey: "ProductVariantID",
|
|
400
|
+
as: "WishList",
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
Customer.hasMany(WishList, { foreignKey: "CustomerID", as: "WishList" });
|
|
404
|
+
|
|
405
|
+
// Cart and ProductVariant Association
|
|
406
|
+
Cart.belongsTo(ProductVariant, {
|
|
407
|
+
foreignKey: "ProductVariantID",
|
|
408
|
+
as: "ProductVariant",
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
Cart.belongsTo(Customer, { foreignKey: "CustomerID", as: "Customer" });
|
|
412
|
+
|
|
413
|
+
Cart.belongsTo(Inventory, { foreignKey: "InventoryID", as: "Inventory" });
|
|
414
|
+
|
|
415
|
+
return { ...models };
|
|
416
|
+
};
|
|
417
|
+
module.exports = initializeModels;
|
package/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const initializeModels = require('./dbconnection/Connect');
|
|
4
|
+
|
|
5
|
+
const enums = {};
|
|
6
|
+
const enumDir = path.join(__dirname, 'enum');
|
|
7
|
+
fs.readdirSync(enumDir).forEach((file) => {
|
|
8
|
+
if (file.endsWith('.js')) {
|
|
9
|
+
const enumName = path.basename(file, '.js');
|
|
10
|
+
enums[enumName] = require(path.join(enumDir, file));
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const utils = {};
|
|
14
|
+
const utilDir = path.join(__dirname, 'utility');
|
|
15
|
+
fs.readdirSync(utilDir).forEach((file) => {
|
|
16
|
+
if(file.endsWith('.js')){
|
|
17
|
+
const utilName = path.basename(file, '.js');
|
|
18
|
+
utils[utilName] = require(path.join(utilDir, file));
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
module.exports = {initializeModels, enums, utils}
|