add html and subject to resending verification email

This commit is contained in:
andres
2023-08-15 19:08:32 +02:00
parent c532347fa2
commit a32884227a
2 changed files with 20 additions and 3 deletions

View File

@@ -1,6 +1,20 @@
import { IsUUID } from 'class-validator'
import { ApiProperty } from '@nestjs/swagger'
import { IsOptional, IsString, IsUUID } from 'class-validator'
export class ResendVerificationEmailDto {
@IsUUID()
userId: string
@ApiProperty({
description: `HTML template to be sent in the email;\n ##name## will be replaced with the user's name; \n ##token## will be replaced with the password recovery token`,
example: `<b>Hello, ##name##!</b><br/>Please confirm your email by clicking on the link below:<br/><a href="http://localhost:3000/confirm-email/##token##">Confirm email</a>. If it doesn't work, copy and paste the following link in your browser:<br/>http://localhost:3000/confirm-email/##token##`,
})
@IsOptional()
@IsString()
html?: string
/** Email subject */
@IsOptional()
@IsString()
subject?: string
}

View File

@@ -3,9 +3,10 @@ import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'
import { UsersRepository } from '../../users/infrastructure/users.repository'
import { UsersService } from '../../users/services/users.service'
import { ResendVerificationEmailDto } from '../dto'
export class ResendVerificationEmailCommand {
constructor(public readonly userId: string) {}
constructor(public readonly body: ResendVerificationEmailDto) {}
}
@CommandHandler(ResendVerificationEmailCommand)
@@ -18,7 +19,7 @@ export class ResendVerificationEmailHandler
) {}
async execute(command: ResendVerificationEmailCommand) {
const user = await this.usersRepository.findUserById(command.userId)
const user = await this.usersRepository.findUserById(command.body.userId)
if (!user) {
throw new NotFoundException('User not found')
@@ -34,6 +35,8 @@ export class ResendVerificationEmailHandler
email: updatedUser.user.email,
name: updatedUser.user.name,
verificationToken: updatedUser.verificationToken,
html: command.body.html,
subject: command.body.subject,
})
if (!updatedUser) {
throw new NotFoundException('User not found')