separation du css et du html

This commit is contained in:
serveur
2026-10-17 23:14:07 +02:00
parent 24f42133ad
commit a54031e313
6 changed files with 620 additions and 450 deletions
+18 -1
View File
@@ -94,7 +94,7 @@ const nettoyerTexte = (valeur) => String(valeur ?? "").replace(/\s+/g, " ").trim
// ---------- API ----------
async function api(req, res, url) {
const [, ressource, id] = url.pathname.split("/").filter(Boolean); // /api/<ressource>/<id>
const [, ressource, id, action] = url.pathname.split("/").filter(Boolean); // /api/<ressource>/<id>/<action>
if (ressource === "events" && req.method === "GET") {
res.writeHead(200, {
@@ -136,6 +136,23 @@ async function api(req, res, url) {
return envoyerJson(res, 200, todos);
}
// POST /api/todos/:id/move { beforeId } : place la tâche juste avant beforeId (ou à la fin si null)
// Un déplacement = une seule tâche qui bouge : pas de conflit si quelqu'un d'autre modifie la liste en même temps
if (id && action === "move" && req.method === "POST") {
const corps = await lireJson(req);
const index = todos.findIndex((t) => t.id === id);
if (index === -1) return envoyerJson(res, 404, { erreur: "Tâche introuvable" });
const [tache] = todos.splice(index, 1);
const cible = typeof corps.beforeId === "string" ? todos.findIndex((t) => t.id === corps.beforeId) : -1;
if (cible === -1) todos.push(tache);
else todos.splice(cible, 0, tache);
sauvegarder();
diffuser();
return envoyerJson(res, 200, todos);
}
if (action) return envoyerJson(res, 404, { erreur: "Introuvable" });
// PATCH /api/todos/:id { done?, text? }
if (id && req.method === "PATCH") {
const tache = todos.find((t) => t.id === id);