Skip to content

Commit

Permalink
fix: code postal contrôlé par mongo mais pas dans zod ce qui faisait …
Browse files Browse the repository at this point in the history
…un échec silencieux à l'insert (#3275)
  • Loading branch information
rap2hpoutre authored Oct 6, 2023
1 parent 6db22a6 commit 6801072
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/src/common/validation/utils/zodPrimitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
INE_REGEX,
NIR_LOOSE_REGEX,
ZOD_3_22_2_EMAIL_REGEX_PATTERN,
CODE_POSTAL_REGEX,
} from "@/common/constants/validations";

import { telephoneConverter } from "./frenchTelephoneNumber";
Expand Down Expand Up @@ -302,8 +303,12 @@ export const primitivesV3 = {
),
adresse: z.string().trim().describe("Adresse de l'apprenant"),
code_postal: z.preprocess(
(v: any) => (v ? String(v) : v),
z.string().trim().describe("Code postal de l'apprenant")
(v: any) => (v ? String(v).trim().padStart(5, "0") : v),
z
.string()
.trim()
.regex(CODE_POSTAL_REGEX, "Le code postal doit faire 5 caractères numériques exactement")
.describe("Code postal de l'apprenant")
),
sexe: z.preprocess(
(v: any) => (v ? String(v).trim().replace("H", "M").replace("1", "M").replace("2", "F") : v),
Expand Down

0 comments on commit 6801072

Please sign in to comment.