feat: add PUT and DELETE /api/sessions/:id/notes endpoints
Made-with: Cursor
This commit is contained in:
@@ -245,6 +245,48 @@ router.delete('/:id', authenticateToken, (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Update session notes (admin only)
|
||||
router.put('/:id/notes', authenticateToken, (req, res) => {
|
||||
try {
|
||||
const { notes } = req.body;
|
||||
|
||||
const session = db.prepare('SELECT id FROM sessions WHERE id = ?').get(req.params.id);
|
||||
if (!session) {
|
||||
return res.status(404).json({ error: 'Session not found' });
|
||||
}
|
||||
|
||||
db.prepare('UPDATE sessions SET notes = ? WHERE id = ?').run(notes, req.params.id);
|
||||
|
||||
const updated = db.prepare(`
|
||||
SELECT s.*, COUNT(sg.id) as games_played
|
||||
FROM sessions s
|
||||
LEFT JOIN session_games sg ON s.id = sg.session_id
|
||||
WHERE s.id = ?
|
||||
GROUP BY s.id
|
||||
`).get(req.params.id);
|
||||
|
||||
res.json(updated);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Clear session notes (admin only)
|
||||
router.delete('/:id/notes', authenticateToken, (req, res) => {
|
||||
try {
|
||||
const session = db.prepare('SELECT id FROM sessions WHERE id = ?').get(req.params.id);
|
||||
if (!session) {
|
||||
return res.status(404).json({ error: 'Session not found' });
|
||||
}
|
||||
|
||||
db.prepare('UPDATE sessions SET notes = NULL WHERE id = ?').run(req.params.id);
|
||||
|
||||
res.json({ success: true });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Get games played in a session
|
||||
router.get('/:id/games', (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user