mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: accept/reject rehersal and get response information
This commit is contained in:
parent
247323654e
commit
5730a9fe3c
5 changed files with 142 additions and 2 deletions
|
|
@ -16,6 +16,7 @@ router.get(
|
|||
location: r.location,
|
||||
proposedBy: r.proposed_by,
|
||||
proposedByName: r.proposed_by_name,
|
||||
votes: r.votes,
|
||||
}))
|
||||
);
|
||||
})
|
||||
|
|
@ -68,4 +69,31 @@ router.delete(
|
|||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/:id/vote',
|
||||
asyncHandler(async (req, res) => {
|
||||
const { vote } = req.body || {};
|
||||
if (!['accept', 'reject'].includes(vote)) {
|
||||
return res.status(400).json({ error: 'invalid_vote' });
|
||||
}
|
||||
const rehearsal = await rehearsalsRepo.findById(req.params.id);
|
||||
if (!rehearsal) return res.status(404).json({ error: 'not_found' });
|
||||
const saved = await rehearsalsRepo.upsertVote(req.params.id, req.user.id, vote);
|
||||
res.json({
|
||||
id: saved.id,
|
||||
rehearsalId: saved.rehearsal_id,
|
||||
userId: saved.user_id,
|
||||
vote: saved.vote,
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/:id/vote',
|
||||
asyncHandler(async (req, res) => {
|
||||
await rehearsalsRepo.removeVote(req.params.id, req.user.id);
|
||||
res.status(204).end();
|
||||
})
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue