-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
111 lines (83 loc) · 2.77 KB
/
server.js
File metadata and controls
111 lines (83 loc) · 2.77 KB
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
var express = require('express');
var bodyParser = require('body-parser')
var cors = require('cors')
var app = express();
app.use(cors())
//Mysql Database Connection parameters
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
port:3306,
user: "root",
password: "admin",
database: 'hms'
});
//Connecting to mysql database
con.connect(function(err) {
if (err) throw err;
console.log(" Database Connected!");
});
// create application/json parser
var jsonParser = bodyParser.json()
//POST Request for Hall Reservation Form.....
app.post('/api/hall/hallReservation',jsonParser,function(req,res){
var jsondata = req.body;
var values = [];
values.push(
jsondata.customerName,
jsondata.phoneNumber,
jsondata.emailId,
jsondata.eventName,
jsondata.bookingDate,
jsondata.fromTime,
jsondata.toTime,
jsondata.noOfAttendees,
jsondata.specialRequest,
);
console.log("inserting values in database for hall_reservation table ....")
//Bulk insert using nested array [ [a,b],[c,d] ] will be flattened to (a,b),(c,d)
con.query('INSERT INTO hall_reservation (customer_name,phone_number,email_id,event_name,booking_date,from_time,to_time,no_of_attendees,special_request) VALUES (?)', [values], function(err,result) {
if(err) {
console.log(err);
res.send('Error');
}
else {
let response = 'Successfully Hall Reserved with Id: '+result.insertId;
console.log(response)
res.send(response);
}
});
});
//POST Request for Table Reservation
app.post('/api/table/tableReservation',jsonParser,function(req,res){
var jsondata = req.body;
var values = [];
values.push(
jsondata.customerName,
jsondata.phoneNumber,
jsondata.emailId,
jsondata.bookingDate,
jsondata.startTime,
jsondata.noOfAttendees,
jsondata.specialRequest,
);
console.log("inserting values in database for hall_reservation table ....")
//Bulk insert using nested array [ [a,b],[c,d] ] will be flattened to (a,b),(c,d)
con.query('INSERT INTO table_reservation (customer_name,phone_number,email_id,booking_date,start_time,no_of_attendees,special_request) VALUES (?)', [values], function(err,result) {
if(err) {
console.log(err);
res.send('Error');
}
else {
let response = 'Successfully Table Reserved with Reference Id: '+result.insertId;
console.log(response)
res.send(response);
}
});
});
// Server Configurations.....
var server = app.listen(8080,function(){
var host = server.address().address
var port = server.address().port
console.log("Restaurant Server app is listening at http://%s:%s",host,port);
})