diff --git a/src/external-services/mailjet/mailjet.types.ts b/src/external-services/mailjet/mailjet.types.ts index 714fa9d6..ba919039 100644 --- a/src/external-services/mailjet/mailjet.types.ts +++ b/src/external-services/mailjet/mailjet.types.ts @@ -97,6 +97,7 @@ export const MailjetTemplates = { ONBOARDING_J3_PROFILE_COMPLETION: 6129711, REFERER_ONBOARDING_CONFIRMATION: 6324339, REFERED_CANDIDATE_FINALIZE_ACCOUNT: 6324039, + ADMIN_NEW_REFERER_NOTIFICATION: 6328158, } as const; export type MailjetTemplateKey = keyof typeof MailjetTemplates; diff --git a/src/mails/mails.service.ts b/src/mails/mails.service.ts index 59d7cb57..fb8c21b8 100644 --- a/src/mails/mails.service.ts +++ b/src/mails/mails.service.ts @@ -79,9 +79,7 @@ export class MailsService { }); } - async sendWelcomeMail( - user: Pick - ) { + async sendWelcomeMail(user: User) { const { candidatesAdminMail } = getAdminMailsFromZone(user.zone); if (user.role === UserRoles.COACH) { @@ -866,6 +864,19 @@ export class MailsService { }, }); } + + async sendAdminNewRefererNotificationMail(referer: User) { + const adminFromZone = getAdminMailsFromZone(referer.zone); + await this.queuesService.addToWorkQueue(Jobs.SEND_MAIL, { + toEmail: adminFromZone.candidatesAdminMail, + templateId: MailjetTemplates.ADMIN_NEW_REFERER_NOTIFICATION, + variables: { + refererFirstName: referer.firstName, + refererLastName: referer.lastName, + refererProfileUrl: `${process.env.FRONTEND_URL}/backoffice/admin/membres/${referer.id}`, + }, + }); + } } const getRoleString = (user: User): string => { diff --git a/src/users-creation/users-creation.controller.ts b/src/users-creation/users-creation.controller.ts index 72fd68fe..620df3ad 100644 --- a/src/users-creation/users-creation.controller.ts +++ b/src/users-creation/users-creation.controller.ts @@ -231,17 +231,14 @@ export class UsersCreationController { gender: createUserRegistrationDto.gender, }); - if ( - createUserRegistrationDto.program === Programs.BOOST || - createUserRegistrationDto.role === UserRoles.REFERER - ) { - await this.usersCreationService.sendWelcomeMail({ - id: createdUser.id, - firstName: createdUser.firstName, - role: createdUser.role, - zone: createdUser.zone, - email: createdUser.email, - }); + if (createUserRegistrationDto.program === Programs.BOOST) { + await this.usersCreationService.sendWelcomeMail(createdUser); + } + + if (createUserRegistrationDto.role === UserRoles.REFERER) { + await this.usersCreationService.sendAdminNewRefererNotificationMail( + createdUser + ); } await this.usersCreationService.sendVerificationMail(createdUser); diff --git a/src/users-creation/users-creation.service.ts b/src/users-creation/users-creation.service.ts index e8487fb0..da26088e 100644 --- a/src/users-creation/users-creation.service.ts +++ b/src/users-creation/users-creation.service.ts @@ -72,9 +72,7 @@ export class UsersCreationService { return this.mailsService.sendNewAccountMail(user, token); } - async sendWelcomeMail( - user: Pick - ) { + async sendWelcomeMail(user: User) { return this.mailsService.sendWelcomeMail(user); } @@ -95,6 +93,10 @@ export class UsersCreationService { return this.usersService.sendMailsAfterMatching(candidateId); } + async sendAdminNewRefererNotificationMail(referer: User) { + return this.mailsService.sendAdminNewRefererNotificationMail(referer); + } + async updateUserCandidatByCandidateId( candidateId: string, updateUserCandidatDto: Partial