Skip to content

Commit

Permalink
fix: utilisation de la regex dans mongo (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
remy-auricoste authored Nov 22, 2023
1 parent dfb6b66 commit ec10518
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
7 changes: 4 additions & 3 deletions server/src/services/etablissement.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions shared/models/referentielOpco.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
3 changes: 3 additions & 0 deletions shared/models/unsubscribeOF.model.ts
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down

0 comments on commit ec10518

Please sign in to comment.