feat: edition complete d'une activite existante
This commit is contained in:
@@ -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.' });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user