Fix delivery reconciliation data type errors and improve server validation

Address Zod validation errors by ensuring correct data types are sent from the frontend and transformed on the backend, specifically for amounts and dates, to resolve 500 server errors during delivery updates.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/kMVZi4q
This commit is contained in:
michaelschal committed 2025-08-12 11:44:44 +00:00
1 parent 7da24cfbe1
commit 15b4f7c9bd
4 files changed
+129 -6

No files matched your search

+19 -2
View File
@@ -690,7 +690,24 @@ export async function registerRoutes(app: Express): Promise<Server> {
}
console.log('🔄 Updating delivery:', { id, data: req.body, user: user.id });
const data = insertDeliverySchema.partial().parse(req.body);
// Transform data types before validation
const transformedData = { ...req.body };
// Convert decimal amounts to strings (schema expects string for decimal fields)
if (transformedData.blAmount !== undefined && transformedData.blAmount !== null) {
transformedData.blAmount = transformedData.blAmount.toString();
}
if (transformedData.invoiceAmount !== undefined && transformedData.invoiceAmount !== null) {
transformedData.invoiceAmount = transformedData.invoiceAmount.toString();
}
// Convert validatedAt to Date object (schema expects Date for timestamp fields)
if (transformedData.validatedAt && typeof transformedData.validatedAt === 'string') {
transformedData.validatedAt = new Date(transformedData.validatedAt);
}
const data = insertDeliverySchema.partial().parse(transformedData);
const updatedDelivery = await storage.updateDelivery(id, data);
console.log('✅ Delivery updated successfully:', { id, updatedDelivery });
@@ -721,7 +738,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
// Auto-valider le rapprochement
await storage.updateDelivery(id, {
reconciled: true,
validatedAt: new Date()
validatedAt: new Date().toISOString()
});
console.log(`✅ Auto-reconciliation: Delivery #${id} automatically validated for supplier ${supplier.name}`);