se incluyó el registro de sistemas

This commit is contained in:
2025-04-23 15:57:52 -06:00
parent 58b49ba93d
commit 50ac4081a9
9 changed files with 56 additions and 34 deletions
+21 -22
View File
@@ -5,6 +5,7 @@ import {
UploadedFile,
Headers,
UnauthorizedException,
Get,
} from '@nestjs/common';
import { MailService } from './mail.service';
import { ExcelService } from 'src/excel/excel.service';
@@ -13,6 +14,7 @@ import { ApiSendMail, ApiSendMailExcel} from './mail.decorators';
import { Repository } from 'typeorm';
import { Sistema } from 'src/typeorm/votacionesPrueba.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { SistemaService } from 'src/sistema/sistema.service';
@ApiTags('Mail') // Grupo de endpoints
@@ -21,43 +23,35 @@ export class MailController {
constructor(
private readonly mailService: MailService,
private readonly excelService: ExcelService,
private readonly sistemaService: SistemaService,
@InjectRepository(Sistema) private readonly sistemaRepository: Repository<Sistema>,
) {}
// Endpoint para enviar correos a través de una solicitud POST
@Post('send')
@ApiSendMail()
async sendMail(
@Headers() headers:{token:string},
@Body() body: { to: string; subject: string; text: string; fecha_recibido: Date, html:string, adjuntos:any }) {
@Body() body: { to: string; subject: string; text: string; fecha_recibido: Date, html:string, adjuntos:any }
) {
// esta parte hay que rehacerla, se tiene que obtener la contraseña del sistema en base a la clave del sistema.
// debe de existir un modulo para crear contraseñas para las apis y administrar esas contraseñas
/* if (!headers.token) {
throw new UnauthorizedException('Header "Password" es requerido');
} */
/* const sistem = await this.sistemaRepository.findOne({ where: { token: headers.token } });
if (!sistem) {
if (!headers.token) {
throw new UnauthorizedException('Header "token" es requerido');
}
const sistem=await this.sistemaRepository.findOne({where:{token:headers.token}})
if(!sistem){
throw new UnauthorizedException('Password incorrecto');
} */
}
console.log("estos son los archivos adjuntos en el controller",body);
const { to, subject, text, html, fecha_recibido, adjuntos } = body;
const result = await this.mailService.sendMail(to, subject, text,html, fecha_recibido,1,adjuntos); // sistem
const result = await this.mailService.sendMail(to, subject, text,html, fecha_recibido,sistem,adjuntos); // sistem
return result;
@@ -96,4 +90,9 @@ export class MailController {
}
}
}
@Get()
async findAll(){
return await this.mailService.findAll()
}
}