From d02961343a6004325f3753a2068c8e0ce6b86433 Mon Sep 17 00:00:00 2001 From: Manus Date: Wed, 11 Feb 2026 08:18:36 -0500 Subject: [PATCH] =?UTF-8?q?Checkpoint:=20Correction=20de=20l'erreur=20lors?= =?UTF-8?q?=20de=20l'ajout=20d'un=20service=20dans=20la=20liste=20des=20se?= =?UTF-8?q?rvices.=20La=20fonction=20initializeDefaultLists=20v=C3=A9rifie?= =?UTF-8?q?=20maintenant=20les=20doublons=20avant=20insertion.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/db.ts | 26 ++++++++++++++++++-------- todo.md | 4 ++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/server/db.ts b/server/db.ts index 5ec1d8c..a76877d 100644 --- a/server/db.ts +++ b/server/db.ts @@ -537,21 +537,31 @@ export async function initializeDefaultLists(userId: number): Promise { // Initialize default departments const defaultDepartments = ["DSI", "TRAVAUX", "AUTRE"]; + const existingDepts = await db.select().from(departmentList).where(eq(departmentList.userId, userId)); + const existingDeptNames = new Set(existingDepts.map(d => d.name)); + for (const name of defaultDepartments) { - try { - await db.insert(departmentList).values({ userId, name }).onDuplicateKeyUpdate({ set: { name } }); - } catch (error) { - // Ignore duplicate errors + if (!existingDeptNames.has(name)) { + try { + await db.insert(departmentList).values({ userId, name }); + } catch (error) { + // Ignore errors + } } } // Initialize default accounting allocations const defaultAllocations = ["TOUS", "PA", "HEP", "SANITAIRE", "AUTRE"]; + const existingAllocs = await db.select().from(accountingAllocationList).where(eq(accountingAllocationList.userId, userId)); + const existingAllocNames = new Set(existingAllocs.map(a => a.name)); + for (const name of defaultAllocations) { - try { - await db.insert(accountingAllocationList).values({ userId, name }).onDuplicateKeyUpdate({ set: { name } }); - } catch (error) { - // Ignore duplicate errors + if (!existingAllocNames.has(name)) { + try { + await db.insert(accountingAllocationList).values({ userId, name }); + } catch (error) { + // Ignore errors + } } } } diff --git a/todo.md b/todo.md index 5116b57..cdc5b66 100644 --- a/todo.md +++ b/todo.md @@ -206,3 +206,7 @@ - [x] Ajouter les colonnes dans la liste des factures (Invoices.tsx) - [x] Initialiser les valeurs par défaut dans les tables (initializeDefaultLists) - [x] Ajouter le lien "Administration des listes" dans le menu de navigation + +## Bug : Erreur lors de l'ajout d'un service +- [x] Corriger la fonction initializeDefaultLists pour éviter les erreurs de duplication +- [x] Vérifier que l'ajout de services et ventilations fonctionne correctement