Skip to content

Commit

Permalink
fix: ajout des modèles ReferentielOpco, UnsuscribedLbaCompany, Unsusc…
Browse files Browse the repository at this point in the history
…ribedOF (#844)
  • Loading branch information
remy-auricoste authored Nov 22, 2023
1 parent cafb5a2 commit 5bb67ee
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -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<IReferentielOpco>(
{
opco_label: {
Expand All @@ -27,4 +27,6 @@ export const referentielOpcoSchema = new Schema<IReferentielOpco>(
}
)

export default model<IReferentielOpco>("referentielOpco", referentielOpcoSchema)
export const ReferentielOpco = model<IReferentielOpco>("referentielOpco", referentielOpcoSchema)

export default ReferentielOpco

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<IUnsubscribedLbaCompany>(
{
...lbaCompanySchema.obj,
Expand All @@ -22,4 +22,6 @@ const unsubscribedLbaCompanySchema = new Schema<IUnsubscribedLbaCompany>(
}
)

export default model<IUnsubscribedLbaCompany>("unsubscribedbonnesboites", unsubscribedLbaCompanySchema)
export const UnsubscribedLbaCompany = model<IUnsubscribedLbaCompany>("unsubscribedbonnesboites", unsubscribedLbaCompanySchema)

export default UnsubscribedLbaCompany

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<IUnsubscribedOF>(
const unsubscribedOFSchema = new Schema<IUnsubscribedOF>(
{
catalogue_id: {
type: String,
Expand All @@ -24,4 +24,6 @@ const unsubscribedOF = new Schema<IUnsubscribedOF>(
}
)

export default model<IUnsubscribedOF>("unsubscribedOF", unsubscribedOF)
export const UnsubscribeOF = model<IUnsubscribedOF>("unsubscribedOF", unsubscribedOFSchema)

export default UnsubscribeOF

This file was deleted.

12 changes: 9 additions & 3 deletions server/src/jobs/database/validateModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
ZLbaCompany,
ZOptout,
ZRecruiter,
ZReferentielOpco,
ZUnsubscribeOF,
ZUnsubscribedLbaCompany,
ZUserRecruteur,
zFormationCatalogueSchema,
} from "shared/models"
Expand All @@ -29,6 +32,9 @@ import {
LbaCompanyLegacy,
Optout,
Recruiter,
ReferentielOpco,
UnsubscribeOF,
UnsubscribedLbaCompany,
UserRecruteur,
eligibleTrainingsForAppointmentHistory,
} from "@/common/model/index"
Expand Down Expand Up @@ -95,11 +101,11 @@ export async function validateModels(): Promise<void> {
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)
Expand Down
3 changes: 1 addition & 2 deletions server/src/services/etablissement.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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"

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"
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/formulaire.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ export const getJob = async (id: string | ObjectId): Promise<IJob | null> => {
*/
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`,
Expand Down
7 changes: 7 additions & 0 deletions shared/helpers/zodHelpers/zodPrimitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,11 @@ export const extensions = {
tags: z.array(z.string()).nullish(),
})
.strict(),
buildEnum: (enumObject: Record<string, string>) => {
const values = Object.values(enumObject)
if (!values.length) {
throw new Error("inattendu : enum vide")
}
return z.enum([values[0], ...values.slice(1)])
},
}
5 changes: 4 additions & 1 deletion shared/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 13 additions & 0 deletions shared/models/referentielOpco.model.ts
Original file line number Diff line number Diff line change
@@ -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<typeof ZReferentielOpco>
12 changes: 12 additions & 0 deletions shared/models/unsubscribeOF.model.ts
Original file line number Diff line number Diff line change
@@ -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<typeof ZUnsubscribeOF>
10 changes: 10 additions & 0 deletions shared/models/unsubscribedLbaCompany.model.ts
Original file line number Diff line number Diff line change
@@ -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<typeof ZUnsubscribedLbaCompany>

0 comments on commit 5bb67ee

Please sign in to comment.