2020-05-10 22:25:08 +00:00
|
|
|
const Participant = require('../api/models/participantModel');
|
|
|
|
|
|
|
|
async function validateParticipantID(req, res, next) {
|
2020-08-28 12:08:13 +00:00
|
|
|
const { id } = req.params;
|
2020-05-10 22:25:08 +00:00
|
|
|
|
|
|
|
try {
|
2020-08-28 12:08:13 +00:00
|
|
|
const participant = await Participant.getParticipantById(id);
|
2020-05-10 22:25:08 +00:00
|
|
|
if (typeof participant == 'undefined') {
|
|
|
|
res.status(404).json({
|
|
|
|
message: `Participant with id ${id} doesn't exist.`,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
res.status(500).json({
|
2020-08-28 12:08:13 +00:00
|
|
|
message: `Failed to get participant with id ${id}`,
|
2020-05-10 22:25:08 +00:00
|
|
|
error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 12:08:13 +00:00
|
|
|
exports.validateParticipantID = validateParticipantID;
|