-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooking_request.js
73 lines (59 loc) · 2.18 KB
/
booking_request.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
let booking, faci;
class Booking {
static async injectDB(conn) {
booking = await conn.db("vms").collection("booking_request")
faci = await conn.db("vms").collection("facilities")
}
static async BookingandReservation(facilities_id, visitor_id, time_slot) {
let i,ii;
// TODO: Check if current booking is full
let result = await booking.find(
{facilities_id: facilities_id, time_slot: time_slot}).toArray();
let facilities = await faci.find(
{facilities_id: facilities_id}).toArray();
console.log("Number of bookings: "+result.length+" Maximum Number of bookings: "+facilities[0].max_no_visitors);
if(result.length <= facilities[0].max_no_visitors){
i = true;
console.log("Booking is available");
} else {
i = false;
console.log("Booking is full");
}
// TODO: Check if duplicate booking
let result2 = await booking.find(
{facilities_id: facilities_id, time_slot: time_slot, visitor_id: visitor_id}).toArray();
if(result2.length == 0){
ii = true;
console.log("You may book this facility");
} else {
ii = false;
console.log("You have already booked this facility");
}
// TODO: Save booking request to database
if(i && ii){
await booking.insertOne({
facilities_id: facilities_id,
visitor_id: visitor_id,
time_slot: time_slot
})
} else {
return false
};
return booking.find({
facilities_id: facilities_id,
visitor_id: visitor_id,
time_slot: time_slot
}).toArray()
}
static async queryBooking(facilities_id) {
// TODO: Query booking request
let result = await booking.find({facilities_id: facilities_id}).toArray();
if(result.length > 0){
console.log("Booking request found");
return result;
} else {
return null;
}
}
}
module.exports = Booking;