Add validateMeetingID middleware to meeting routes

This commit is contained in:
2020-05-11 00:18:09 +02:00
parent e8d8d9e42f
commit 7a0b2b09ba
3 changed files with 88 additions and 69 deletions

View File

@@ -0,0 +1,23 @@
const Meeting = require('../api/models/meetingModel');
async function validateMeetingID(req, res, next) {
const { id } = req.params;
try {
const meeting = await Meeting.getMeetingById(id);
if (typeof meeting == 'undefined') {
return res.status(404).json({
message: `Meeting with id ${id} doesn't exist.`,
});
} else {
next();
}
} catch (error) {
res.status(500).json({
message: `Failed to fetch meeting with id ${id}.`,
error,
});
}
}
exports.validateMeetingID = validateMeetingID;