import PasswordRecoveryTemplate from '@/src/module/libs/mail/templates/password-recovery.template' import { SessionInfo } from '@/src/shared/types/session-metadata.types' import { Token } from '@prisma/generated' import VerificationTemplate from './templates/verification.template' import { MailerService } from '@nestjs-modules/mailer' import { Injectable } from '@nestjs/common' import { ConfigService } from '@nestjs/config' import { render } from '@react-email/components' @Injectable() export class MailService { constructor( private readonly configService: ConfigService, private readonly mailerService: MailerService, ) {} public async sendVerificationToken(email: string, token: Token['token']) { const domain = this.configService.getOrThrow('ALLOWED_ORIGIN') const html = await render(VerificationTemplate({ domain, token })) // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- todo fixme return this.sendMail(email, 'Верификация аккаунта', html) } public async sendPasswordResetToken(email: string, token: Token['token'], metadata: SessionInfo) { const domain = this.configService.getOrThrow('ALLOWED_ORIGIN') const html = await render(PasswordRecoveryTemplate({ domain, token, metadata })) // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- todo fixme return this.sendMail(email, 'Сброс пароля', html) } private sendMail(email: string, subject: string, html: string) { return this.mailerService.sendMail({ to: email, subject, html, }) } }