backend/middlewares/validateMeetingID.js

23 lines
519 B
JavaScript
Raw Normal View History

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;