diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index af9830d..1e5a2f1 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -6,6 +6,9 @@ import { InfoLoginDto } from './dtos/info-login.dto'; import { accessAttemptMessage } from './enums/message.enum'; import { UserRepository } from '../user/user.repository'; import { InfoEntity } from './entity/info.entity'; +import { MailService } from '../mails/mail.service'; +import { MentorEntity } from '../mentors/entities/mentor.entity'; +import { UserEntity } from '../user/entities/user.entity'; @Injectable() export class AuthService { @@ -13,6 +16,7 @@ export class AuthService { private mentorRepository: MentorRepository, private userRepository: UserRepository, private jwt: JwtService, + private mailService: MailService, ) {} async execute({ email, password, type}: InfoLoginDto) { @@ -22,7 +26,7 @@ export class AuthService { } else { info = await this.userRepository.findUserByEmail(email) } - this.infoConfirm(info); + await this.infoConfirm(info, type); const passwordIsValid = await bcrypt.compare(password, info.password); @@ -52,7 +56,7 @@ export class AuthService { }; } - infoConfirm(info: InfoEntity) { + async infoConfirm(info: InfoEntity, type: string) { if (!info || info.deleted == true) { const message = "invalid e-mail or password" @@ -63,6 +67,10 @@ export class AuthService { if (!info.emailConfirmed) { const message = 'Your account is not activated yet. Check your e-mail inbox for instructions' + + if(type == 'mentor') await this.mailService.mentorSendCreationConfirmation(info as MentorEntity) + if(type == 'user') await this.mailService.userSendCreationConfirmation(info as UserEntity) + throw new HttpException({ message }, HttpStatus.NOT_FOUND) }