diff --git a/back/src/server.js b/back/src/server.js index e41ee41..7810762 100644 --- a/back/src/server.js +++ b/back/src/server.js @@ -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.' }); }); diff --git a/front/src/App.jsx b/front/src/App.jsx index 0e502c6..6eaf255 100644 --- a/front/src/App.jsx +++ b/front/src/App.jsx @@ -805,9 +805,23 @@ export default function App() { )} -
- Coût - {act.cost_shells} 🐚 +
+ + +
+ Coût + {act.cost_shells} 🐚 +
@@ -1241,10 +1255,10 @@ export default function App() {
- {/* Liste des activités existantes avec possibilité de changer leur photo */} + {/* Liste des activités existantes avec possibilité de les modifier */}

- Catalogue actuel (cliquez sur « Modifier l'image » pour changer l'illustration d'une activité existante) : + Catalogue actuel (cliquez sur « Modifier l'activité » pour éditer son nom, coût, emoji, description ou photo) :

{activities.map((a) => ( @@ -1262,12 +1276,16 @@ export default function App() {
-
- {editingActivity.title} -
- - {editingActivity.emoji} {editingActivity.title} ({editingActivity.cost_shells} 🐚) - -
-
- -
- Choisir une image dans la galerie : -
- {PRESET_GALLERY.map((p) => ( - - ))} -
-
- -
-