Fix issue with empty amount fields not saving correctly

Ensure that undefined optional fields in the Avoir update payload are converted to null for proper PostgreSQL compatibility.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/Ii96ETr
This commit is contained in:
michaelschal committed 2025-09-08 20:32:07 +00:00
1 parent 734f8c26c7
commit 011be98ed0
2 files changed
+10 -1

No files matched your search

+10 -1
View File
@@ -2506,7 +2506,16 @@ export async function registerRoutes(app: Express): Promise<Server> {
const validatedData = insertAvoirSchema.partial().parse(req.body);
console.log('💰 PUT Avoir - Validated data:', JSON.stringify(validatedData, null, 2));
const updatedAvoir = await storage.updateAvoir(id, validatedData);
// ✅ FIX: Convertir undefined en null pour les champs optionnels (important pour PostgreSQL)
const dataForDb: any = {
...validatedData,
amount: validatedData.amount === undefined ? null : validatedData.amount,
invoiceReference: validatedData.invoiceReference === undefined ? null : validatedData.invoiceReference,
comment: validatedData.comment === undefined ? null : validatedData.comment,
};
console.log('💰 PUT Avoir - Data for DB (undefined → null):', JSON.stringify(dataForDb, null, 2));
const updatedAvoir = await storage.updateAvoir(id, dataForDb);
console.log('✅ Avoir updated:', id, 'by user:', user.id);
// 🎯 WEBHOOK QUAND STATUT PASSE À "Reçu"