Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: utilisation de la regex dans mongo #847

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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