Skip to content

Commit

Permalink
feat: LBA-2329 gestion hardbounce des candidats PRDV deuxième phase (#…
Browse files Browse the repository at this point in the history
…1429)

* feat: ajustements

* feat: cleaning
  • Loading branch information
alanlr authored Aug 20, 2024
1 parent 001a96c commit 092eb58
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
13 changes: 11 additions & 2 deletions server/src/services/appointment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 11 additions & 2 deletions server/src/services/emails.service.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const createOrUpdateUserByEmail = async (email: string, update: Partial<I
}

export const cleanHardbouncedAppointmentUser = async (email: string) => {
const fakeEmail = `hardbounced-${randomUUID()}@faux-domaine.fr`
const fakeEmail = `email-blacklist-par-lba-${randomUUID()}@faux-domaine.fr`
await getDbCollection("users").findOneAndUpdate(
{ email },
{
Expand Down

0 comments on commit 092eb58

Please sign in to comment.