1. toggleVote wrapped in transaction (race condition fix) 2. FeedbackPanel fetch calls now surface errors via onError/toast 3. Extracted resolveBoard/hasCollectionRole to shared board-access.js 4. AnnotationStore uses monotonic version counter for snapshots 5. PinOverlay uses object pool instead of destroy/recreate on refresh 6. canvasObjects prop memoized with useMemo 7. PinOverlay store subscription cleaned up on unmount 8. Comment content capped at 5000 chars (backend validation) 10. anchor_type validated to 'object' or 'point'
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
const { Router } = require('express');
|
|
const { authMiddleware } = require('../auth');
|
|
const { getVotesByBoard, toggleVote } = require('../db');
|
|
const { resolveBoard } = require('./board-access');
|
|
|
|
const router = Router();
|
|
|
|
router.use(authMiddleware);
|
|
|
|
// GET /api/boards/:boardId/votes — all votes for board
|
|
router.get('/:boardId/votes', (req, res) => {
|
|
try {
|
|
const result = resolveBoard(req, res, 'viewer');
|
|
if (!result) return;
|
|
|
|
const votes = getVotesByBoard(req.params.boardId);
|
|
return res.json({ votes });
|
|
} catch (err) {
|
|
console.error('[votes] list error:', err);
|
|
return res.status(500).json({ error: 'Internal server error' });
|
|
}
|
|
});
|
|
|
|
// POST /api/boards/:boardId/votes — toggle vote
|
|
router.post('/:boardId/votes', (req, res) => {
|
|
try {
|
|
const result = resolveBoard(req, res, 'viewer');
|
|
if (!result) return;
|
|
|
|
const { object_id } = req.body;
|
|
if (!object_id) {
|
|
return res.status(400).json({ error: 'object_id is required' });
|
|
}
|
|
|
|
const active = toggleVote(req.params.boardId, object_id, req.user.id);
|
|
|
|
const io = req.app.get('io');
|
|
if (io) {
|
|
io.to(`board:${req.params.boardId}`).emit('vote:toggle', {
|
|
boardId: req.params.boardId,
|
|
objectId: object_id,
|
|
userId: req.user.id,
|
|
active,
|
|
});
|
|
}
|
|
|
|
return res.json({ active });
|
|
} catch (err) {
|
|
console.error('[votes] toggle error:', err);
|
|
return res.status(500).json({ error: 'Internal server error' });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|