24 lines
554 B
JavaScript
24 lines
554 B
JavaScript
const Participant = require('../api/models/participantModel');
|
|
|
|
async function validateParticipantID(req, res, next) {
|
|
const { id } = req.params;
|
|
|
|
try {
|
|
const participant = await Participant.getParticipantById(id);
|
|
if (typeof participant == 'undefined') {
|
|
res.status(404).json({
|
|
message: `Participant with id ${id} doesn't exist.`,
|
|
});
|
|
} else {
|
|
next();
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: `Failed to get participant with id ${id}`,
|
|
error,
|
|
});
|
|
}
|
|
}
|
|
|
|
exports.validateParticipantID = validateParticipantID;
|