73 lines
1.6 KiB
JavaScript
73 lines
1.6 KiB
JavaScript
|
let express = require('express');
|
||
|
let router = express.Router();
|
||
|
|
||
|
let Participant = require('../models/participantModel');
|
||
|
|
||
|
router.post('/', async (req, res) => {
|
||
|
const data = { ...req.body };
|
||
|
|
||
|
try {
|
||
|
const [participant] = await Participant.addParticipant(data);
|
||
|
res.status(201).json(participant);
|
||
|
} catch (error) {
|
||
|
res.status(500).json({
|
||
|
message: 'Failed to add new participant.',
|
||
|
error,
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
router.put('/:account_id-:meeting_id', async (req, res) => {
|
||
|
const data = { ...req.body };
|
||
|
const { account_id, meeting_id } = req.params;
|
||
|
|
||
|
try {
|
||
|
const participant = await Participant.updateParticipant(
|
||
|
data,
|
||
|
account_id,
|
||
|
meeting_id,
|
||
|
);
|
||
|
res.status(200).json(...participant);
|
||
|
} catch (error) {
|
||
|
res.status(500).json({
|
||
|
message: 'Failed to update participant.',
|
||
|
error,
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
router.delete('/:account_id-:meeting_id', async (req, res) => {
|
||
|
const { account_id, meeting_id } = req.params;
|
||
|
|
||
|
try {
|
||
|
const participant = await Participant.deleteParticipant(
|
||
|
account_id,
|
||
|
meeting_id,
|
||
|
);
|
||
|
res.status(200).json({
|
||
|
message: `Participant with id ${account_id}-${meeting_id} successfully deleted.`,
|
||
|
});
|
||
|
} catch (error) {
|
||
|
res.status(500).json({
|
||
|
message: 'Failed to delete participant.',
|
||
|
error,
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
router.get('/:account_id-:meeting_id', async (req, res) => {
|
||
|
const { account_id, meeting_id } = req.params;
|
||
|
|
||
|
try {
|
||
|
const participant = await Participant.getParticipantById(
|
||
|
account_id,
|
||
|
meeting_id,
|
||
|
);
|
||
|
res.status(200).json(participant);
|
||
|
} catch (error) {
|
||
|
res.status(500).json({ message: "Participant doesn't exist.", error });
|
||
|
}
|
||
|
});
|
||
|
|
||
|
module.exports = router;
|