-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall.js
42 lines (33 loc) · 1 KB
/
call.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
const Call = require("../models/call");
const CallParticipants = require("../models/callParticipants");
const checkIsAdminCall = async (req, res, next) => {
const call = await Call.findOne({
where: {
admin: req.session.userId,
},
});
if (!call) {
req.isAdmin = false;
} else {
req.isAdmin = true;
}
console.log(req.isAdmin);
next();
};
const checkUserAlreadyInCall = async (req, res, next) => {
const userInCall = await CallParticipants.findOne({
where: { userId: req.user.id },
});
if (userInCall && userInCall.isInCall) {
return res.render("already-in-call", { userId: req.user.id });
}
next();
};
const checkCallExists = async (req, res, next) => {
const call = await Call.findOne({ where: { id: req.params.callId } });
if (!call) {
return res.status(400).json({ error: "Invalid Call ID" });
}
next();
};
module.exports = { checkIsAdminCall, checkUserAlreadyInCall, checkCallExists };