-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbookRoutes.js
61 lines (51 loc) · 1.77 KB
/
bookRoutes.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
var express = require('express'),
router = express.Router(),
app = express(),
bodyParser = require('body-parser');
PlayGround = require('./models/PlayGrounds'),
Booking = require('./models/Booking'),
User = require('./models/Users');
router.get('/confirm-:id',function(req, res) {
var venueId = req.params.id;
PlayGround.findOne({_id: venueId}, function(err, pg) {
var user = req.user;
var book = new Booking( {
date: req.query.date,
duration: req.query.time,
by: user,
venue: pg
});
book.save(function(err,boo) {
if(err) {
console.log("booking not saved");
res.send("booking not saved");
}else {
User.update({_id: user.id}, { "$push": { "bookings": boo._id } }, function(err, raw) {
if(err) {
console.log("not updated");
}else {
console.log("updated user: " + raw);
res.redirect("/user");
}
});
}
})
})
})
router.route('/:id')
.get(function(req, res) {
var venueId = req.params.id;
//console.log(req);
PlayGround.findOne({_id: venueId}, function(err, pg) {
//console.log(pg);
if(req.isAuthenticated()) {
var user = req.user;
req.pg = pg;
res.render('booking.ejs', { messages: "loggedIn", pg, user});
}
else {
res.render('booking.ejs', { messages: null, pg, user});
}
});
});
module.exports = router;