diff --git a/client/src/pages/Avoirs.tsx b/client/src/pages/Avoirs.tsx index a3797fc..6f2b5a8 100644 --- a/client/src/pages/Avoirs.tsx +++ b/client/src/pages/Avoirs.tsx @@ -88,7 +88,7 @@ const avoirSchema = z.object({ }) ]).optional(), comment: z.string().optional(), - commercialProcessed: z.boolean().optional(), + commercialProcessed: z.boolean().default(false), status: z.enum(["En attente de demande", "Demandé", "Reçu"]).optional(), }); @@ -272,6 +272,11 @@ export default function Avoirs() { // Handle edit form submission const onEditSubmit = (data: AvoirFormData) => { if (selectedAvoir) { + console.log('💰 Editing avoir - Form data sent:', { + originalCommercial: selectedAvoir.commercialProcessed, + formCommercial: data.commercialProcessed, + fullData: data + }); editAvoirMutation.mutate({ id: selectedAvoir.id, data }); } }; diff --git a/server/routes.ts b/server/routes.ts index c096368..05f0cb0 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -2501,10 +2501,19 @@ export async function registerRoutes(app: Express): Promise { } } - const updatedAvoir = await storage.updateAvoir(id, req.body); + // ✅ CRITICAL FIX: Validate data with Zod schema (partial) + console.log('💰 PUT Avoir - Raw body received:', JSON.stringify(req.body, null, 2)); + 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); console.log('✅ Avoir updated:', id, 'by user:', user.id); res.json(updatedAvoir); } catch (error) { + if (error instanceof z.ZodError) { + console.error('❌ [PUT AVOIR] ERREURS VALIDATION ZOD:', JSON.stringify(error.errors, null, 2)); + return res.status(400).json({ message: "Validation error", errors: error.errors }); + } console.error("Error updating avoir:", error); res.status(500).json({ message: "Failed to update avoir" }); }