forked from CreativeC0der/RailwayProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
115 lines (90 loc) · 2.78 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// get the client
const express = require('express')
const hbs = require('express-handlebars')
const mysql = require('mysql2');
//import Routes
const aboutRoute = require('./Routes/about');
const contactRoute = require('./Routes/contact');
const dashboardRoute = require('./Routes/dashboard');
const bookRoute = require('./Routes/book');
const adminRoute = require('./Routes/admin-dashboard');
const app = express();
//connectiong to DB
const connection = mysql.createConnection({
host: 'sql6.freemysqlhosting.net',
user: 'sql6634593',
password: 'E1r1TMmUtF',
database: 'sql6634593'
});
connection.connect((err) => {
if (err)
console.log(err)
else {
console.log("Connected to DB")
app.listen(5000,() => {
console.log('listening on port 3000');
});
}
})
global.connection = connection;
// initialize views and Handlebars
app.engine('handlebars', hbs.engine({
helpers: {
ifEquals: function (arg1, arg2, options) {
return arg1 === arg2 ? options.fn(this) : options.inverse(this);
},
jsonStringify: function (context) {
return JSON.stringify(context);
}
}
}));
app.set('view engine', 'handlebars')
app.set('views', './Views')
app.use(express.urlencoded({ extended: true }))
//Routing
app.get('/home', (req, res) => {
res.render('home', {})
})
//posting to /passnger-login (need to implemnet this)
app.post('/passenger-login', (req, res) => {
console.log(req.body);
query = `insert into passenger values(
"${req.body.name}",
"${req.body.acc_num}",
"${req.body.email}",
"${req.body.phone}",
"${req.body.address}"
)`
connection.query(query, (err, results, fields) => {
if (err)
console.log(err);
res.redirect('/passenger-login');
})
})
app.get('/passenger-login', (req, res) => {
res.render('login', {})
})
app.get('/admin-login', (req, res) => {
res.render('admin-login', {})
})
app.get('/signup', (req, res) => {
res.render('signup', {})
})
app.get('/about', aboutRoute);
app.get('/contact', contactRoute);
app.post('/dashboard', dashboardRoute);
app.post('/dashboard/cancel', dashboardRoute);
app.get('/book', bookRoute);
app.post('/book/overview', bookRoute);
app.post('/book/payment', bookRoute);
app.post('/admin-dashboard', adminRoute);
app.post('/admin-dashboard/add-station', adminRoute);
app.post('/admin-dashboard/add-train', adminRoute);
app.post('/admin-dashboard/add-seat', adminRoute);
//need to implemnet @shrijon
//posting station_code
app.post('/admin-dashboard/delete-station', adminRoute);
//posting train_number, train_name
app.post('/admin-dashboard/delete-train', adminRoute);
//posting train_number, seat_type
app.post('/admin-dashboard/delete-seat', adminRoute);