From bb2f8f580259fcf70b1fe7d66714385932fdd1b0 Mon Sep 17 00:00:00 2001 From: "Paul G." Date: Sat, 17 Aug 2024 19:49:35 +0200 Subject: [PATCH] fix: change type for schema v2 (#3813) Co-authored-by: Paul Gaucher --- .../common/actions/v2/person.v2.actions.ts | 4 ++-- .../validationSchema.test.ts.snap | 24 ++++++++++++------- shared/models/data/v2/formation.v2.model.ts | 4 ++-- shared/models/data/v2/organisme.v2.model.ts | 4 ++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/server/src/common/actions/v2/person.v2.actions.ts b/server/src/common/actions/v2/person.v2.actions.ts index 920d38131..cf457b2f8 100644 --- a/server/src/common/actions/v2/person.v2.actions.ts +++ b/server/src/common/actions/v2/person.v2.actions.ts @@ -16,7 +16,7 @@ export const getPersonV2 = async (nom: string, prenom: string, date_de_naissance return personV2Db().findOne({ nom: nom.toLowerCase(), prenom: prenom.toLowerCase(), - date_de_naissance: date_de_naissance, + date_de_naissance: new Date(date_de_naissance), }); }; export const insertPersonV2 = async (nom: string, prenom: string, date_de_naissance: Date) => { @@ -26,6 +26,6 @@ export const insertPersonV2 = async (nom: string, prenom: string, date_de_naissa updated_at: new Date(), nom: nom.toLowerCase(), prenom: prenom.toLowerCase(), - date_de_naissance: date_de_naissance, + date_de_naissance: new Date(date_de_naissance), }); }; diff --git a/server/src/common/mongodb/__snapshots__/validationSchema.test.ts.snap b/server/src/common/mongodb/__snapshots__/validationSchema.test.ts.snap index feca20393..eb634b808 100644 --- a/server/src/common/mongodb/__snapshots__/validationSchema.test.ts.snap +++ b/server/src/common/mongodb/__snapshots__/validationSchema.test.ts.snap @@ -8932,7 +8932,10 @@ exports[`validation-schema should create validation schema for formationV2: form "bsonType": "objectId", }, "cfd": { - "bsonType": "string", + "bsonType": [ + "string", + "null", + ], }, "created_at": { "bsonType": "date", @@ -8947,7 +8950,10 @@ exports[`validation-schema should create validation schema for formationV2: form "bsonType": "objectId", }, "rncp": { - "bsonType": "string", + "bsonType": [ + "string", + "null", + ], }, "updated_at": { "bsonType": "date", @@ -8960,8 +8966,6 @@ exports[`validation-schema should create validation schema for formationV2: form "updated_at", "organisme_responsable_id", "organisme_formateur_id", - "rncp", - "cfd", ], } `; @@ -10892,10 +10896,16 @@ exports[`validation-schema should create validation schema for organismeV2: orga "bsonType": "bool", }, "siret": { - "bsonType": "string", + "bsonType": [ + "string", + "null", + ], }, "uai": { - "bsonType": "string", + "bsonType": [ + "string", + "null", + ], }, "updated_at": { "bsonType": "date", @@ -10906,8 +10916,6 @@ exports[`validation-schema should create validation schema for organismeV2: orga "draft", "created_at", "updated_at", - "uai", - "siret", ], } `; diff --git a/shared/models/data/v2/formation.v2.model.ts b/shared/models/data/v2/formation.v2.model.ts index 5bc712961..7d3276797 100644 --- a/shared/models/data/v2/formation.v2.model.ts +++ b/shared/models/data/v2/formation.v2.model.ts @@ -13,8 +13,8 @@ export const zFormationV2 = z.object({ updated_at: z.date(), organisme_responsable_id: zObjectId, organisme_formateur_id: zObjectId, - rncp: z.string(), - cfd: z.string(), + rncp: z.string().nullish(), + cfd: z.string().nullish(), }); export type IFormationV2 = z.output; diff --git a/shared/models/data/v2/organisme.v2.model.ts b/shared/models/data/v2/organisme.v2.model.ts index 07251b40f..e15d261b9 100644 --- a/shared/models/data/v2/organisme.v2.model.ts +++ b/shared/models/data/v2/organisme.v2.model.ts @@ -11,8 +11,8 @@ export const zOrganismeV2 = z.object({ draft: z.boolean(), created_at: z.date(), updated_at: z.date(), - uai: z.string(), - siret: z.string(), + uai: z.string().nullish(), + siret: z.string().nullish(), current_organisme_id: zObjectId.nullish(), });