Refactor MailController and MailService for improved readability and consistency
This commit is contained in:
+16
-27
@@ -7,58 +7,47 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { MailService } from './mail.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { ApiSendMail} from './mail.decorators';
|
||||
import { ApiSendMail } from './mail.decorators';
|
||||
import { SistemaService } from 'src/sistema/sistema.service';
|
||||
import { SendCorreoDto } from 'src/mail/dto/send-email.dto';
|
||||
import { AuthService } from 'src/auth/auth.service';
|
||||
|
||||
|
||||
@ApiTags('Mail') // Grupo de endpoints
|
||||
@Controller('mail')
|
||||
export class MailController {
|
||||
constructor(
|
||||
private readonly sistemaService: SistemaService,
|
||||
private readonly mailService: MailService,
|
||||
// private readonly excelService: ExcelService,
|
||||
private readonly authService: AuthService
|
||||
|
||||
// private readonly excelService: ExcelService,
|
||||
private readonly authService: AuthService,
|
||||
) {}
|
||||
|
||||
// Endpoint para enviar correos a través de una solicitud POST
|
||||
|
||||
|
||||
|
||||
@Post('send')
|
||||
@ApiSendMail()
|
||||
async sendMail(
|
||||
@Headers() headers:{token:string},
|
||||
@Body() body: SendCorreoDto
|
||||
@Headers() headers: { token: string },
|
||||
@Body() body: SendCorreoDto,
|
||||
) {
|
||||
|
||||
if (!headers.token) {
|
||||
throw new UnauthorizedException('Header "token" es requerido');
|
||||
}
|
||||
|
||||
const result =
|
||||
await this.mailService.sendMail(body,headers.token)
|
||||
.then((value) => {
|
||||
console.log("ya acabe el correo", value);
|
||||
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
|
||||
|
||||
const result = await this.mailService
|
||||
.sendMail(body, headers.token)
|
||||
.then((value) => {
|
||||
console.log('ya acabe el correo', value);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
// sistem
|
||||
return result;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
|
||||
@Post('send-excel')
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
|
||||
Reference in New Issue
Block a user