-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminController.js
More file actions
50 lines (44 loc) · 1.78 KB
/
Copy pathadminController.js
File metadata and controls
50 lines (44 loc) · 1.78 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
module.exports = {
//export the Admin.js as a object, and set the getAdmin method
//as a property of the object. This is an common approach to export module in JS
getAdmin: (db) => {
return (req, res) => {
let sql = 'SELECT * FROM appointments';
let query = db.query(sql, (err, appointment) => {
if(err) throw err;
sql = 'SELECT * from users';
query = db.query(sql, (err, user) => {
if(err) throw err;
sql = 'SELECT * from dogs';
query = db.query(sql, (err, dog) =>{
if(err) throw err;
appointment.forEach(appointment => {
dog.forEach(dog =>{
if(dog.id===appointment.dogid){
appointment.dogname = dog.name;
}
})
})
appointment.forEach(appointment => {
user.forEach(user =>{
if(user.id===appointment.userid){
appointment.username = user.firstname+' '+user.lastname ;
}
})
})
appointment.sort((a,b) => {
if(a.date > b.date) {return 1;}
if(a.date < b.date) {return -1;}
if(a.slot > b.slot) {return 1;}
if(a.slot < b.slot) {return -1;}
return 0;
})
res.render('admin', {
appointments: appointment,
})
})
})
})
}
}
}