import { Injectable } from '@nestjs/common' ; import { UsersService } from '../users/users.service' ; import * as bcrypt from 'bcrypt' ; import { MailerService } from '@nestjs-modules/mailer' ; import { RegisterUserDto } from './dto/register-user.dto' ; import { IUsers } from './../users/interfaces/users.interface' ; @ Injectable ( ) export class RegisterService { constructor ( private readonly usersService , private readonly mailerService ) { } public async register ( registerUserDto ) { registerUserDto . password = bcrypt . hashSync ( registerUserDto . password , 8 ) ; this . sendMailRegisterUser ( registerUserDto ) ; return this . usersService . create ( registerUserDto ) ; } private sendMailRegisterUser ( user ) { this . mailerService . sendMail ( { to : user . email , from : 'from@example.com' , subject : 'Registration successful ✔' , text : 'Registration successful!' , template : 'index' , context : { title : 'Registration successfully' , description : "You did it! You registered!, You're successfully registered.✔" , nameUser : user . name , } , } ) . then ( response => { console . log ( response ) ; console . log ( 'User Registration: Send Mail successfully!' ) ; } ) . catch ( err => { console . log ( err ) ; console . log ( 'User Registration: Send Mail Failed!' ) ; } ) ; } }