fix: issues in authentication mail messages.

This commit is contained in:
Ahmed Bouhuolia
2020-09-05 13:29:39 +02:00
parent 9ee7ed89ec
commit 481ca8aa8b
13 changed files with 159 additions and 71 deletions

View File

@@ -2,8 +2,17 @@ import { Container, Inject } from 'typedi';
import AuthenticationService from '@/services/Authentication';
export default class WelcomeEmailJob {
@Inject()
authService: AuthenticationService;
/**
* Constructor method.
* @param {Agenda} agenda
*/
constructor(agenda) {
agenda.define(
'reset-password-mail',
{ priority: 'high' },
this.handler.bind(this),
);
}
/**
* Handle send welcome mail job.
@@ -11,17 +20,18 @@ export default class WelcomeEmailJob {
* @param {Function} done
*/
public async handler(job, done: Function): Promise<void> {
const { email, organizationName, firstName } = job.attrs.data;
const { user, token } = job.attrs.data;
const Logger = Container.get('logger');
const authService = Container.get(AuthenticationService);
Logger.info(`Send reset password mail - started: ${job.attrs.data}`);
Logger.info(`[send_reset_password] started: ${job.attrs.data}`);
try {
await this.authService.mailMessages.sendResetPasswordMessage();
Logger.info(`Send reset password mail - finished: ${job.attrs.data}`);
await authService.mailMessages.sendResetPasswordMessage(user, token);
Logger.info(`[send_reset_password] finished: ${job.attrs.data}`);
done()
} catch (error) {
Logger.info(`Send reset password mail - error: ${job.attrs.data}, error: ${error}`);
Logger.info(`[send_reset_password] error: ${job.attrs.data}, error: ${error}`);
done(error);
}
}