mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-12 01:37:40 +02:00
Fix issue where commercial processed status incorrectly retained on update
Implement Zod validation on PUT /avoirs/:id endpoint to ensure correct data handling for commercialProcessed field, defaulting it to false and logging validation errors. 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/2DtJTqh
This commit is contained in:
1 parent
4129ae68d0
commit
80b9d387c7
2 files changed
+16
-2
No files matched your search
@@ -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 });
|
||||
}
|
||||
};
|
||||
|
||||
+10
-1
@@ -2501,10 +2501,19 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
}
|
||||
|
||||
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" });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user