Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -46,9 +46,9 @@ router.post('/:id/vote', requireUser, (req, res) => {
|
||||
const id = Number(req.params.id);
|
||||
if (!getStation(id)) return res.status(404).json({ error: 'not found' });
|
||||
const raw = req.body?.value;
|
||||
const value = raw === 1 || raw === '1' || raw === 'up' ? 1
|
||||
: raw === -1 || raw === '-1' || raw === 'down' ? -1
|
||||
: raw === 0 || raw === '0' || raw === null || raw === 'clear' ? 0
|
||||
const value = raw === 1 || raw === '1' || raw === 'up' ? 1
|
||||
: raw === -1 || raw === '-1' || raw === 'down' ? -1
|
||||
: raw === 0 || raw === '0' || raw === null || raw === 'clear' ? 0
|
||||
: NaN;
|
||||
if (Number.isNaN(value)) return res.status(400).json({ error: 'value must be 1, -1 or 0' });
|
||||
res.json(castVote(req.user.id, id, value));
|
||||
|
||||
Reference in New Issue
Block a user