-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
88 lines (82 loc) · 3.01 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
const express = require('express');
function createRouter(db) {
const router = express.Router();
const owner = '';
// the routes are defined here
router.get("/", function(request, result) {
result.send("Hello World");
});
router.post('/register', (req, res, next) => {
var data = req.body;
console.log("Data :=" + data);
db.query(
'Insert into users SET ?', data,
(error, results) => {
if (error) {
console.error(error);
res.status(500).json(error);
} else {
// res.status(200).json({ status: 'ok' });
res.status(200).json(results);
console.log("Entering Data" + JSON.stringify(results));
}
}
);
});
router.post('/upload', (req, res, next) => {
var data = req.body;
console.log("Data :=" + JSON.stringify(data), Object.keys(data).length);
for (var i = 0; i < Object.keys(data).length; i++) {
// console.log("Data :=" + data[i]);
db.query(
'Insert into jsonDetails SET ?', data[i],
(error, results) => {
if (error) {
console.error(error);
// res.status(500).json(error);
} else {
// res.status(200).json({ status: 'ok' });
// res.status(200).json(results);
console.log("Entering Data" + JSON.stringify(results));
}
}
);
}
res.status(200).json({ status: 'ok' });
});
router.get('/details', (req, res, next) => {
db.query(
'Select * from jsonDetails',
(error, results) => {
if (error) {
console.error(error);
res.status(500).json({ status: 'error' });
} else {
// res.status(200).json({ status: 'ok' });
res.status(200).json(results);
console.log("Retrieved Booking Data" + JSON.stringify(results));
}
}
);
});
router.get('/login/:email/:password', (req, res, next) => {
var email = req.params.email;
var password = req.params.password;
console.log("Data :=" + email, password);
db.query(
'Select * from users where email = ? AND password = ?', [email, password],
(error, results) => {
if (error) {
console.error(error);
res.status(500).json({ status: 'Error' });
} else {
// res.status(200).json({ status: 'ok' });
res.status(200).json(results);
console.log("Retrieved User Details :: " + JSON.stringify(results));
}
}
);
});
return router;
}
module.exports = createRouter;