From 5bb67ee3486f5342e16af6e822002068348e5cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Auricoste?= Date: Wed, 22 Nov 2023 11:12:57 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20ajout=20des=20mod=C3=A8les=20Referentiel?= =?UTF-8?q?Opco,=20UnsuscribedLbaCompany,=20UnsuscribedOF=20(#844)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../referentielOpco/referentielOpco.schema.ts | 8 +++++--- .../schema/referentielOpco/referentielOpco.types.ts | 7 ------- .../unsubscribedLbaCompany.schema.ts | 8 +++++--- .../unsubscribedLbaCompany.types.ts | 8 -------- .../schema/unsubscribedOF/unsubscribeOF.schema.ts | 10 ++++++---- .../schema/unsubscribedOF/unsubscribeOF.types.ts | 5 ----- server/src/jobs/database/validateModels.ts | 12 +++++++++--- server/src/services/etablissement.service.ts | 3 +-- server/src/services/formulaire.service.ts | 2 +- shared/helpers/zodHelpers/zodPrimitives.ts | 7 +++++++ shared/models/index.ts | 5 ++++- shared/models/referentielOpco.model.ts | 13 +++++++++++++ shared/models/unsubscribeOF.model.ts | 12 ++++++++++++ shared/models/unsubscribedLbaCompany.model.ts | 10 ++++++++++ 14 files changed, 73 insertions(+), 37 deletions(-) delete mode 100644 server/src/common/model/schema/referentielOpco/referentielOpco.types.ts delete mode 100644 server/src/common/model/schema/unsubscribedLbaCompany/unsubscribedLbaCompany.types.ts delete mode 100644 server/src/common/model/schema/unsubscribedOF/unsubscribeOF.types.ts create mode 100644 shared/models/referentielOpco.model.ts create mode 100644 shared/models/unsubscribeOF.model.ts create mode 100644 shared/models/unsubscribedLbaCompany.model.ts diff --git a/server/src/common/model/schema/referentielOpco/referentielOpco.schema.ts b/server/src/common/model/schema/referentielOpco/referentielOpco.schema.ts index 25654d6383..748012f63d 100644 --- a/server/src/common/model/schema/referentielOpco/referentielOpco.schema.ts +++ b/server/src/common/model/schema/referentielOpco/referentielOpco.schema.ts @@ -1,8 +1,8 @@ +import { IReferentielOpco } from "shared/models" + import { OPCOS } from "../../../../services/constant.service" import { model, Schema } from "../../../mongodb" -import { IReferentielOpco } from "./referentielOpco.types" - export const referentielOpcoSchema = new Schema( { opco_label: { @@ -27,4 +27,6 @@ export const referentielOpcoSchema = new Schema( } ) -export default model("referentielOpco", referentielOpcoSchema) +export const ReferentielOpco = model("referentielOpco", referentielOpcoSchema) + +export default ReferentielOpco diff --git a/server/src/common/model/schema/referentielOpco/referentielOpco.types.ts b/server/src/common/model/schema/referentielOpco/referentielOpco.types.ts deleted file mode 100644 index 9abb1bd1d2..0000000000 --- a/server/src/common/model/schema/referentielOpco/referentielOpco.types.ts +++ /dev/null @@ -1,7 +0,0 @@ -interface IReferentielOpco { - opco_label: string - siret_code: string - emails: string[] -} - -export type { IReferentielOpco } diff --git a/server/src/common/model/schema/unsubscribedLbaCompany/unsubscribedLbaCompany.schema.ts b/server/src/common/model/schema/unsubscribedLbaCompany/unsubscribedLbaCompany.schema.ts index edc642078f..ecf840e332 100644 --- a/server/src/common/model/schema/unsubscribedLbaCompany/unsubscribedLbaCompany.schema.ts +++ b/server/src/common/model/schema/unsubscribedLbaCompany/unsubscribedLbaCompany.schema.ts @@ -1,8 +1,8 @@ +import { IUnsubscribedLbaCompany } from "shared" + import { model, Schema } from "../../../mongodb.js" import { lbaCompanySchema } from "../lbaCompany/lbaCompany.schema.js" -import { IUnsubscribedLbaCompany } from "./unsubscribedLbaCompany.types.js" - const unsubscribedLbaCompanySchema = new Schema( { ...lbaCompanySchema.obj, @@ -22,4 +22,6 @@ const unsubscribedLbaCompanySchema = new Schema( } ) -export default model("unsubscribedbonnesboites", unsubscribedLbaCompanySchema) +export const UnsubscribedLbaCompany = model("unsubscribedbonnesboites", unsubscribedLbaCompanySchema) + +export default UnsubscribedLbaCompany diff --git a/server/src/common/model/schema/unsubscribedLbaCompany/unsubscribedLbaCompany.types.ts b/server/src/common/model/schema/unsubscribedLbaCompany/unsubscribedLbaCompany.types.ts deleted file mode 100644 index ccafbf145c..0000000000 --- a/server/src/common/model/schema/unsubscribedLbaCompany/unsubscribedLbaCompany.types.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { ILbaCompany } from "shared" - -interface IUnsubscribedLbaCompany extends ILbaCompany { - unsubscribe_date: Date - unsubscribe_reason: string -} - -export type { IUnsubscribedLbaCompany } diff --git a/server/src/common/model/schema/unsubscribedOF/unsubscribeOF.schema.ts b/server/src/common/model/schema/unsubscribedOF/unsubscribeOF.schema.ts index e4329b4d20..c8487c054d 100644 --- a/server/src/common/model/schema/unsubscribedOF/unsubscribeOF.schema.ts +++ b/server/src/common/model/schema/unsubscribedOF/unsubscribeOF.schema.ts @@ -1,8 +1,8 @@ -import { model, Schema } from "../../../mongodb" +import { IUnsubscribedOF } from "shared/models" -import { IUnsubscribedOF } from "./unsubscribeOF.types" +import { model, Schema } from "../../../mongodb" -const unsubscribedOF = new Schema( +const unsubscribedOFSchema = new Schema( { catalogue_id: { type: String, @@ -24,4 +24,6 @@ const unsubscribedOF = new Schema( } ) -export default model("unsubscribedOF", unsubscribedOF) +export const UnsubscribeOF = model("unsubscribedOF", unsubscribedOFSchema) + +export default UnsubscribeOF diff --git a/server/src/common/model/schema/unsubscribedOF/unsubscribeOF.types.ts b/server/src/common/model/schema/unsubscribedOF/unsubscribeOF.types.ts deleted file mode 100644 index b931250a06..0000000000 --- a/server/src/common/model/schema/unsubscribedOF/unsubscribeOF.types.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface IUnsubscribedOF { - catalogue_id: string - establishment_siret: string - unsubscribe_date: Date -} diff --git a/server/src/jobs/database/validateModels.ts b/server/src/jobs/database/validateModels.ts index b350c9e1eb..cf2fb84ca2 100644 --- a/server/src/jobs/database/validateModels.ts +++ b/server/src/jobs/database/validateModels.ts @@ -10,6 +10,9 @@ import { ZLbaCompany, ZOptout, ZRecruiter, + ZReferentielOpco, + ZUnsubscribeOF, + ZUnsubscribedLbaCompany, ZUserRecruteur, zFormationCatalogueSchema, } from "shared/models" @@ -29,6 +32,9 @@ import { LbaCompanyLegacy, Optout, Recruiter, + ReferentielOpco, + UnsubscribeOF, + UnsubscribedLbaCompany, UserRecruteur, eligibleTrainingsForAppointmentHistory, } from "@/common/model/index" @@ -95,11 +101,11 @@ export async function validateModels(): Promise { await validateModel(Optout, ZOptout) await validateModel(Recruiter, ZRecruiter) // await validateModel(ReferentielOnisep, ZReferentielOnisep) - // await validateModel(ReferentielOpco, ZReferentielOpco) + await validateModel(ReferentielOpco, ZReferentielOpco) // await validateModel(ReferentielRome, ZReferentielRome) // await validateModel(RncpRomes, ZRncpRomes) - // await validateModel(UnsubscribeOF, ZUnsubscribeOF) - // await validateModel(UnsubscribedLbaCompany, ZUnsubscribedLbaCompany) + await validateModel(UnsubscribeOF, ZUnsubscribeOF) + await validateModel(UnsubscribedLbaCompany, ZUnsubscribedLbaCompany) // await validateModel(User, ZUser) await validateModel(UserRecruteur, ZUserRecruteur) await validateModel(eligibleTrainingsForAppointmentHistory, ZEligibleTrainingsForAppointmentSchema) diff --git a/server/src/services/etablissement.service.ts b/server/src/services/etablissement.service.ts index b24758fe81..7ff74c0bbb 100644 --- a/server/src/services/etablissement.service.ts +++ b/server/src/services/etablissement.service.ts @@ -1,7 +1,7 @@ import { AxiosResponse } from "axios" import Boom from "boom" import type { FilterQuery } from "mongoose" -import { IEtablissement, ILbaCompany, IRecruiter, IReferentielData, IUserRecruteur } from "shared" +import { IEtablissement, ILbaCompany, IRecruiter, IReferentielData, IReferentielOpco, IUserRecruteur } from "shared" import { BusinessErrorCodes } from "shared/constants/errorCodes" import { ETAT_UTILISATEUR } from "shared/constants/recruteur" @@ -9,7 +9,6 @@ import { getStaticFilePath } from "@/common/utils/getStaticFilePath" import { getHttpClient } from "@/common/utils/httpUtils" import { Etablissement, LbaCompany, LbaCompanyLegacy, ReferentielOpco, UnsubscribeOF, UserRecruteur } from "../common/model/index" -import { IReferentielOpco } from "../common/model/schema/referentielOpco/referentielOpco.types" import { isEmailFromPrivateCompany, isEmailSameDomain } from "../common/utils/mailUtils" import { sentryCaptureException } from "../common/utils/sentryUtils" import config from "../config" diff --git a/server/src/services/formulaire.service.ts b/server/src/services/formulaire.service.ts index d3c5855f20..9d08f57d31 100644 --- a/server/src/services/formulaire.service.ts +++ b/server/src/services/formulaire.service.ts @@ -544,8 +544,8 @@ export const getJob = async (id: string | ObjectId): Promise => { */ export async function sendDelegationMailToCFA(email: string, offre: IJob, recruiter: IRecruiter, siret_code: string) { const unsubscribeOF = await UnsubscribeOF.findOne({ establishment_siret: siret_code }) - const unsubscribeToken = createCfaUnsubscribeToken(email, siret_code) if (unsubscribeOF) return + const unsubscribeToken = createCfaUnsubscribeToken(email, siret_code) await mailer.sendEmail({ to: email, subject: `Une entreprise recrute dans votre domaine`, diff --git a/shared/helpers/zodHelpers/zodPrimitives.ts b/shared/helpers/zodHelpers/zodPrimitives.ts index a276701cc9..3910701293 100644 --- a/shared/helpers/zodHelpers/zodPrimitives.ts +++ b/shared/helpers/zodHelpers/zodPrimitives.ts @@ -74,4 +74,11 @@ export const extensions = { tags: z.array(z.string()).nullish(), }) .strict(), + buildEnum: (enumObject: Record) => { + const values = Object.values(enumObject) + if (!values.length) { + throw new Error("inattendu : enum vide") + } + return z.enum([values[0], ...values.slice(1)]) + }, } diff --git a/shared/models/index.ts b/shared/models/index.ts index 4f304ff119..03d1a56769 100644 --- a/shared/models/index.ts +++ b/shared/models/index.ts @@ -14,6 +14,9 @@ export * from "./metiers.model" export * from "./metiersdavenir.model" export * from "./optout.model" export * from "./recruiter.model" +export * from "./referentielOpco.model" export * from "./rome.model" -export * from "./usersRecruteur.model" export * from "./session.model" +export * from "./unsubscribedLbaCompany.model" +export * from "./unsubscribeOF.model" +export * from "./usersRecruteur.model" diff --git a/shared/models/referentielOpco.model.ts b/shared/models/referentielOpco.model.ts new file mode 100644 index 0000000000..938a63c036 --- /dev/null +++ b/shared/models/referentielOpco.model.ts @@ -0,0 +1,13 @@ +import { OPCOS } from "../constants/recruteur" +import { extensions } from "../helpers/zodHelpers/zodPrimitives" +import { z } from "../helpers/zodWithOpenApi" + +export const ZReferentielOpco = z + .object({ + opco_label: extensions.buildEnum(OPCOS).describe("Dénomination de l'opco"), + siret_code: extensions.siret.describe("Siret de l'établissement"), + emails: z.array(z.string().email()).describe("Liste des emails disponibles pour l'établissement"), + }) + .strict() + +export type IReferentielOpco = z.output diff --git a/shared/models/unsubscribeOF.model.ts b/shared/models/unsubscribeOF.model.ts new file mode 100644 index 0000000000..03dab37d2f --- /dev/null +++ b/shared/models/unsubscribeOF.model.ts @@ -0,0 +1,12 @@ +import { extensions } from "../helpers/zodHelpers/zodPrimitives" +import { z } from "../helpers/zodWithOpenApi" + +export const ZUnsubscribeOF = z + .object({ + catalogue_id: z.string().describe("Id de l'organisme dans le catalogue"), + establishment_siret: extensions.siret.describe("Le Siret de l'organisme de formation"), + unsubscribe_date: z.coerce.date().describe("Date de désinscription"), + }) + .strict() + +export type IUnsubscribedOF = z.output diff --git a/shared/models/unsubscribedLbaCompany.model.ts b/shared/models/unsubscribedLbaCompany.model.ts new file mode 100644 index 0000000000..a644f62f3d --- /dev/null +++ b/shared/models/unsubscribedLbaCompany.model.ts @@ -0,0 +1,10 @@ +import { z } from "../helpers/zodWithOpenApi" + +import { ZLbaCompany } from "./lbaCompany.model" + +export const ZUnsubscribedLbaCompany = ZLbaCompany.extend({ + unsubscribe_date: z.coerce.date().describe("Date de désinscription"), + unsubscribe_reason: z.string().describe("Raison de la désinscription"), +}).strict() + +export type IUnsubscribedLbaCompany = z.output