feat: edition complete d'une activite existante

This commit is contained in:
2026-11-13 12:36:54 +01:00
parent 9c48217c36
commit 174fc6872e
2 changed files with 215 additions and 70 deletions

View File

@@ -270,13 +270,17 @@ app.patch('/api/activities/:id', (req, res) => {
const emoji = req.body.emoji ?? existing.emoji;
const image_url = req.body.image_url !== undefined ? req.body.image_url : existing.image_url;
const cost_shells = req.body.cost_shells !== undefined ? Number(req.body.cost_shells) : existing.cost_shells;
const status = req.body.status ?? existing.status;
const current_shells = req.body.current_shells !== undefined ? Math.max(0, Number(req.body.current_shells)) : existing.current_shells;
let status = req.body.status ?? existing.status;
if (current_shells >= cost_shells && status === 'ACTIVE') {
status = 'UNLOCKED';
}
db.prepare(`
UPDATE activities
SET title = ?, description = ?, emoji = ?, image_url = ?, cost_shells = ?, status = ?
SET title = ?, description = ?, emoji = ?, image_url = ?, cost_shells = ?, current_shells = ?, status = ?
WHERE id = ?
`).run(title, description, emoji, image_url, cost_shells, status, id);
`).run(title, description, emoji, image_url, cost_shells, current_shells, status, id);
res.json({ message: 'Activité mise à jour.' });
});