Checkpoint: Correction de l'erreur lors de l'ajout d'un service dans la liste des services. La fonction initializeDefaultLists vérifie maintenant les doublons avant insertion.
This commit is contained in:
26
server/db.ts
26
server/db.ts
@@ -537,21 +537,31 @@ export async function initializeDefaultLists(userId: number): Promise<void> {
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
todo.md
4
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
|
||||
|
||||
Reference in New Issue
Block a user