diff --git a/server/src/services/appointment.service.ts b/server/src/services/appointment.service.ts index 13ea21ec46..4796ea92e8 100644 --- a/server/src/services/appointment.service.ts +++ b/server/src/services/appointment.service.ts @@ -189,10 +189,19 @@ export const processAppointmentToCfaWebhookEvent = async (payload) => { return true } -export const isHardbounceEventFromAppointment = async (payload) => { +export const isHardbounceEventFromAppointmentApplicant = async (payload) => { const messageId = payload["message-id"] - const appointment = await findOne({ $or: [{ "to_cfa_mails.message_id": messageId }, { "to_applicant_mails.message_id": messageId }] }) + const appointment = await findOne({ "to_applicant_mails.message_id": messageId }) + if (appointment) { + return true + } + return false +} +export const isHardbounceEventFromAppointmentCfa = async (payload) => { + const messageId = payload["message-id"] + + const appointment = await findOne({ "to_cfa_mails.message_id": messageId }) if (appointment) { return true } diff --git a/server/src/services/emails.service.ts b/server/src/services/emails.service.ts index ea8a7cd51b..a76d7b5d87 100644 --- a/server/src/services/emails.service.ts +++ b/server/src/services/emails.service.ts @@ -1,5 +1,10 @@ import { addEmailToBlacklist, processApplicationHardbounceEvent, removeEmailFromLbaCompanies } from "@/services/application.service" -import { isHardbounceEventFromAppointment, processAppointmentToApplicantWebhookEvent, processAppointmentToCfaWebhookEvent } from "@/services/appointment.service" +import { + isHardbounceEventFromAppointmentApplicant, + isHardbounceEventFromAppointmentCfa, + processAppointmentToApplicantWebhookEvent, + processAppointmentToCfaWebhookEvent, +} from "@/services/appointment.service" import { BrevoEventStatus } from "./brevo.service" import { disableEligibleTraininForAppointmentWithEmail } from "./eligibleTrainingsForAppointment.service" @@ -27,10 +32,14 @@ export const processHardBounceWebhookEvent = async (payload) => { origin = "candidature_spontanee" } - if (await isHardbounceEventFromAppointment(payload)) { + if (await isHardbounceEventFromAppointmentCfa(payload)) { origin = "prise_de_rdv" } + if (await isHardbounceEventFromAppointmentApplicant(payload)) { + origin = "candidat_prise_de_rdv" + } + if (await isHardbounceEventFromEtablissement(payload)) { origin = "invitation_prise_de_rdv" } diff --git a/server/src/services/user.service.ts b/server/src/services/user.service.ts index 7c1892f35f..301ee162d1 100644 --- a/server/src/services/user.service.ts +++ b/server/src/services/user.service.ts @@ -36,7 +36,7 @@ export const createOrUpdateUserByEmail = async (email: string, update: Partial { - const fakeEmail = `hardbounced-${randomUUID()}@faux-domaine.fr` + const fakeEmail = `email-blacklist-par-lba-${randomUUID()}@faux-domaine.fr` await getDbCollection("users").findOneAndUpdate( { email }, {