fix: email sending

This commit is contained in:
Kakious 2024-07-27 11:34:47 -04:00
parent 4200e41987
commit 8a283f46e7
2 changed files with 10 additions and 8 deletions

View file

@ -1,16 +1,18 @@
import { Controller, Get, Redirect } from '@nestjs/common'; import { Controller, Get, Redirect, UseGuards } from '@nestjs/common';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { PostalClientService } from 'nestjs-postal-client'; import { LoginGuard } from './auth/guard/login.guard';
import { MailService } from './mail/mail.service';
@Controller() @Controller()
export class AppController { export class AppController {
constructor( constructor(
private readonly appService: AppService, private readonly appService: AppService,
private readonly postal: PostalClientService, private readonly mailService: MailService,
) {} ) {}
@Get() @Get()
@Redirect('/auth/login') @Redirect('/auth/login')
@UseGuards(LoginGuard)
getHello(): any { getHello(): any {
return; return;
} }

View file

@ -110,8 +110,8 @@ export class MailService {
* @returns The content of the template * @returns The content of the template
*/ */
private async readHtmlTemplate(templateName: string): Promise<string> { private async readHtmlTemplate(templateName: string): Promise<string> {
return await readFile( return (
path.join(__dirname, '../..', 'mail/html', `${templateName}.hbs`), await readFile(path.join(__dirname, '../..', 'mail/html', `${templateName}.hbs`))
).toString(); ).toString();
} }
@ -121,8 +121,8 @@ export class MailService {
* @returns The content of the template * @returns The content of the template
*/ */
private async readTextTemplate(templateName: string): Promise<string> { private async readTextTemplate(templateName: string): Promise<string> {
return await readFile( return (
path.join(__dirname, '../..', 'mail/text', `${templateName}.txt`), await readFile(path.join(__dirname, '../..', 'mail/text', `${templateName}.txt`))
).toString(); ).toString();
} }
@ -132,7 +132,7 @@ export class MailService {
* @returns The content of the template * @returns The content of the template
*/ */
private async fetchTemplate(templateName: string): Promise<{ html: string; text: string }> { private async fetchTemplate(templateName: string): Promise<{ html: string; text: string }> {
// await both promises // await both promises for html and text
const [html, text] = await Promise.all([ const [html, text] = await Promise.all([
this.readHtmlTemplate(templateName), this.readHtmlTemplate(templateName),
this.readTextTemplate(templateName), this.readTextTemplate(templateName),