| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #203 | Réceptions — Parcours de pesée multi-étapes | ## Description de la PR [#203] Réceptions — Parcours de pesée multi-étapes ## Modification du .env ## Check list - [x] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: #3 Reviewed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Co-authored-by: AUTIN Tristan <tristan@yuno.malio.fr> Co-committed-by: AUTIN Tristan <tristan@yuno.malio.fr>
18 lines
510 B
TypeScript
18 lines
510 B
TypeScript
import type { ZodError } from 'zod'
|
|
|
|
export type FieldErrors<T extends Record<string, unknown>> = Partial<Record<keyof T, string>>
|
|
|
|
export const mapZodErrors = <T extends Record<string, unknown>>(error: ZodError<T>): FieldErrors<T> => {
|
|
const flattened = error.flatten().fieldErrors
|
|
const result: FieldErrors<T> = {}
|
|
|
|
for (const key in flattened) {
|
|
const message = flattened[key]?.[0]
|
|
if (message) {
|
|
result[key as keyof T] = message
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|