-
Notifications
You must be signed in to change notification settings - Fork 16
/
server.js
99 lines (85 loc) · 2.15 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
- express is a library that would be used for routing purposes.
*/
const app = require('./app');
const db = require('./models/index');
const serverConfig = require('./configs/server.config');
require('./routes/product.route')(app);
require('./routes/category.route')(app);
require('./routes/auth.route')(app);
require('./routes/cart.route')(app);
db.sequelize.sync({
force: true
}).then(() => {
console.log('Tables dropped and recreated');
init();
});
function init() {
let roles = [
{
name: 'admin'
},
{
name: 'user'
}
];
let categories = [
{
name: 'Electronics',
description: 'This Category Contains all the electronic items'
},
{
name: 'HomeApplicances',
description: 'This Category Contains all the Home Appliances'
}
];
let products = [
{
name: 'iphone 14 pro max',
description: 'MAT KHAREEDO!!!!',
cost: '140000',
categoryId: 1
},
{
name: 'samsung s22',
description: 'device with a cool camera',
cost: '110000',
categoryId: 1
},
{
name: "Prestige Cooker",
description: "You can enjoy cooked meal with this applicance like rice, raajma, pulao, khichdi",
cost: "5000",
categoryId: 2
}
]
db.category
.bulkCreate(categories)
.then(() => {
console.log("Categories table is initialized");
}).catch(err => {
console.log("Error while initializing ategories table");
});
db
.role
.bulkCreate(roles)
.then(() => {
console.log('Roles created successfully');
}).catch(err => {
console.log('error while creating roles');
});
db
.product
.bulkCreate(products)
.then(() => {
console.log('products added');
}).catch(error => {
console.error('error occurred while adding products', error);
})
}
app.listen(serverConfig.PORT, () => {
console.log(`APP IS RUNNING ON PORT: ${serverConfig.PORT}`);
})
/*
/
*/