mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-22 06:28:19 +02:00
Merge pull request #382 from R0m1k3/1.1
Improve validation for the amount field in financial records
This commit is contained in:
2 files changed
+15
-13
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
+15
-13
@@ -71,19 +71,21 @@ 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),
|
||||||
const num = parseFloat(val);
|
z.string().transform((val) => {
|
||||||
if (isNaN(num)) {
|
const num = parseFloat(val);
|
||||||
throw new Error("Montant invalide");
|
if (isNaN(num)) {
|
||||||
}
|
throw new Error("Montant invalide");
|
||||||
if (num <= 0) {
|
}
|
||||||
throw new Error("Le montant doit être supérieur à 0");
|
if (num <= 0) {
|
||||||
}
|
throw new Error("Le montant doit être supérieur à 0");
|
||||||
return num;
|
}
|
||||||
}).optional(),
|
return num;
|
||||||
|
})
|
||||||
|
]).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(),
|
||||||
|
|||||||
Reference in new issue
Block a user