This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
forked from kaustavdm/opentok-video-embed-demo
-
Notifications
You must be signed in to change notification settings - Fork 25
/
meetings_route.js
84 lines (73 loc) · 2.01 KB
/
meetings_route.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
/* global DB */
const router = require('express').Router();
const debug = require('util').debuglog('app');
/**
* Render page for booking appointments
*/
router.get('/book', (req, res) => {
res.locals.user = { role: 'Patient' };
let m_list = DB.meetings_filter(false);
res.render('book_meeting', { meetings: [].concat(m_list.current, m_list.upcoming) });
});
/**
* Handle form for booking appointment
*/
router.post('/book', (req, res, next) => {
let m = DB.meetings_get(parseInt(req.body.meeting_id));
if (m == null) {
next();
return;
};
m.booked = true;
DB.meetings_put(m);
debug(`Booked meeting. ID: ${m.id}`, m);
res.redirect('/dashboard/patient');
});
/**
* View for creating meeting
*/
router.get('/create', (req, res) => {
res.locals.assets.styles.push('flatpickr.min.css');
res.locals.assets.scripts.push('flatpickr.min.js');
res.locals.assets.scripts.push('scheduling_ui.js');
res.locals.user = { role: 'Doctor' };
res.render('create_meeting');
});
/**
* Handle POST request to create new meeeting
*/
router.post('/create', (req, res) => {
const start_time = new Date(req.body.start_date);
const end_time = new Date(start_time.getTime() + (parseInt(req.body.duration) * 60000));
const m = {
id: DB.meetings.length + 1,
start_time: start_time,
end_time: end_time,
booked: false
};
DB.meetings_put(m);
debug(`Created meeting. ID: ${m.id}`, m);
res.redirect('/dashboard/doctor')
});
/**
* View for joining meeting
*/
router.get('/join/:meeting_id', (req, res, next) => {
const m = DB.meetings_get(parseInt(req.params.meeting_id));
if (m == null || !m.booked) {
next();
return;
}
const embed_code = DB.embed_code.replace('DEFAULT_ROOM', `meeting${m.id}`);
if (!embed_code) {
res.render('embed_not_set');
return;
}
if (Date.parse(m.end_time) < Date.now()) {
res.locals.meeting_over = true;
} else {
res.locals.meeting_over = false;
}
res.render('meeting', { embed_code: embed_code, meeting: m });
});
module.exports = router;