Improve validation for the amount field in financial records

Update Zod schema for the 'amount' field to handle various invalid input formats and ensure positive numerical values.

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/KZQgDPI
This commit is contained in:
michaelschal committed 2025-09-08 16:27:09 +00:00
1 parent 45fed62a7a
commit af1783cb3f
2 files changed
+7 -5

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

+7 -5
View File
@@ -71,10 +71,11 @@ const avoirSchema = z.object({
supplierId: z.coerce.number().min(1, "Veuillez sélectionner un fournisseur"), supplierId: z.coerce.number().min(1, "Veuillez sélectionner un fournisseur"),
groupId: z.coerce.number().min(1, "Veuillez sélectionner un magasin"), groupId: z.coerce.number().min(1, "Veuillez sélectionner un magasin"),
invoiceReference: z.string().optional(), invoiceReference: z.string().optional(),
amount: z.string().transform((val) => { amount: z.union([
if (val === "" || val === null || val === undefined) { z.null().transform(() => undefined),
return undefined; z.undefined().transform(() => undefined),
} z.literal("").transform(() => undefined),
z.string().transform((val) => {
const num = parseFloat(val); const num = parseFloat(val);
if (isNaN(num)) { if (isNaN(num)) {
throw new Error("Montant invalide"); throw new Error("Montant invalide");
@@ -83,7 +84,8 @@ const avoirSchema = z.object({
throw new Error("Le montant doit être supérieur à 0"); throw new Error("Le montant doit être supérieur à 0");
} }
return num; return num;
}).optional(), })
]).optional(),
comment: z.string().optional(), comment: z.string().optional(),
commercialProcessed: z.boolean().optional(), commercialProcessed: z.boolean().optional(),
status: z.enum(["En attente de demande", "Demandé", "Reçu"]).optional(), status: z.enum(["En attente de demande", "Demandé", "Reçu"]).optional(),