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

[EN-7599] Mail admin notification creation de compte prescripteur #239

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
1 change: 1 addition & 0 deletions src/external-services/mailjet/mailjet.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 14 additions & 3 deletions src/mails/mails.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ export class MailsService {
});
}

async sendWelcomeMail(
user: Pick<User, 'id' | 'firstName' | 'role' | 'zone' | 'email'>
) {
async sendWelcomeMail(user: User) {
const { candidatesAdminMail } = getAdminMailsFromZone(user.zone);

if (user.role === UserRoles.COACH) {
Expand Down Expand Up @@ -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 => {
Expand Down
19 changes: 8 additions & 11 deletions src/users-creation/users-creation.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/users-creation/users-creation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ export class UsersCreationService {
return this.mailsService.sendNewAccountMail(user, token);
}

async sendWelcomeMail(
user: Pick<User, 'id' | 'firstName' | 'role' | 'zone' | 'email'>
) {
async sendWelcomeMail(user: User) {
return this.mailsService.sendWelcomeMail(user);
}

Expand All @@ -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<UserCandidat>
Expand Down