From ec105184e07896324811bea076d65966e3774a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Auricoste?= Date: Wed, 22 Nov 2023 18:00:35 +0100 Subject: [PATCH] fix: utilisation de la regex dans mongo (#847) --- .../lba_recruteur/opco/constructys/constructysImporter.ts | 2 +- .../src/jobs/lba_recruteur/opco/ocapiat/ocapiatImporter.ts | 2 +- server/src/services/etablissement.service.ts | 7 ++++--- shared/models/referentielOpco.model.ts | 3 +++ shared/models/unsubscribeOF.model.ts | 3 +++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/server/src/jobs/lba_recruteur/opco/constructys/constructysImporter.ts b/server/src/jobs/lba_recruteur/opco/constructys/constructysImporter.ts index f0994d5c64..18f7e12065 100644 --- a/server/src/jobs/lba_recruteur/opco/constructys/constructysImporter.ts +++ b/server/src/jobs/lba_recruteur/opco/constructys/constructysImporter.ts @@ -31,7 +31,7 @@ const importer = async (filePath, remoteFileName, opco_label) => { parseCsv(), filterData((e) => e.Mails), transformData((e) => { - const emails: any[] = [] + const emails: string[] = [] const { Siret, Mails } = e const emailsArray = Mails.split(/,|;| /).filter((x) => x) diff --git a/server/src/jobs/lba_recruteur/opco/ocapiat/ocapiatImporter.ts b/server/src/jobs/lba_recruteur/opco/ocapiat/ocapiatImporter.ts index aa104e13fe..1e97b4fe70 100644 --- a/server/src/jobs/lba_recruteur/opco/ocapiat/ocapiatImporter.ts +++ b/server/src/jobs/lba_recruteur/opco/ocapiat/ocapiatImporter.ts @@ -31,7 +31,7 @@ const importer = async (filePath, remoteFileName, opco_label) => { parseCsv({ trim: true, delimiter: ";" }), filterData((e) => e["Email du contact"]), transformData((e) => { - const emails: any[] = [] + const emails: string[] = [] const Siret = e.Siret const email = e["Email du contact"] diff --git a/server/src/services/etablissement.service.ts b/server/src/services/etablissement.service.ts index 7ff74c0bbb..75ef00d723 100644 --- a/server/src/services/etablissement.service.ts +++ b/server/src/services/etablissement.service.ts @@ -449,11 +449,12 @@ export const isCompanyValid = async (userRecruteur: IUserRecruteur) => { } const siren = siret.slice(0, 9) + const sirenRegex = `^${siren}` // Get all corresponding records using the SIREN number in BonneBoiteLegacy collection const [bonneBoiteLegacyList, bonneBoiteList, referentielOpcoList] = await Promise.all([ - getAllEstablishmentFromLbaCompanyLegacy({ siret: { $regex: siren }, email: { $nin: ["", null] } }), - getAllEstablishmentFromLbaCompany({ siret: { $regex: siren }, email: { $nin: ["", null] } }), - getAllEstablishmentFromOpcoReferentiel({ siret_code: { $regex: siren } }), + getAllEstablishmentFromLbaCompanyLegacy({ siret: { $regex: sirenRegex }, email: { $nin: ["", null] } }), + getAllEstablishmentFromLbaCompany({ siret: { $regex: sirenRegex }, email: { $nin: ["", null] } }), + getAllEstablishmentFromOpcoReferentiel({ siret_code: { $regex: sirenRegex } }), ]) // Format arrays to get only the emails diff --git a/shared/models/referentielOpco.model.ts b/shared/models/referentielOpco.model.ts index 938a63c036..8623de41f5 100644 --- a/shared/models/referentielOpco.model.ts +++ b/shared/models/referentielOpco.model.ts @@ -2,8 +2,11 @@ import { OPCOS } from "../constants/recruteur" import { extensions } from "../helpers/zodHelpers/zodPrimitives" import { z } from "../helpers/zodWithOpenApi" +import { zObjectId } from "./common" + export const ZReferentielOpco = z .object({ + _id: zObjectId, 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"), diff --git a/shared/models/unsubscribeOF.model.ts b/shared/models/unsubscribeOF.model.ts index 03dab37d2f..bf7c060f26 100644 --- a/shared/models/unsubscribeOF.model.ts +++ b/shared/models/unsubscribeOF.model.ts @@ -1,8 +1,11 @@ import { extensions } from "../helpers/zodHelpers/zodPrimitives" import { z } from "../helpers/zodWithOpenApi" +import { zObjectId } from "./common" + export const ZUnsubscribeOF = z .object({ + _id: zObjectId, 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"),