se incluyó el registro de sistemas
This commit is contained in:
BIN
Binary file not shown.
+21
-22
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as nodemailer from 'nodemailer';
|
||||
import * as dotenv from 'dotenv';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Correo, Status } from '../typeorm/votacionesPrueba.entity';
|
||||
import { Correo, Sistema, Status } from '../typeorm/votacionesPrueba.entity';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
@@ -56,9 +56,14 @@ export class MailService {
|
||||
}
|
||||
|
||||
// Función para generar el reporte de correos enviados y fallidos
|
||||
|
||||
async findAll(){
|
||||
const result= await this.correoRepository.find({relations:['id_sistema','id_status']})
|
||||
return result
|
||||
}
|
||||
|
||||
async sendMail(to: string, subject: string, text: string, html: string, fecha_recibido: Date, sistema, adjuntos?: any[] ) {
|
||||
|
||||
|
||||
|
||||
console.log("estos son los archivos adjuntos en el service",adjuntos);
|
||||
|
||||
@@ -100,7 +105,7 @@ export class MailService {
|
||||
let resMail = await this.transporter.sendMail(mailOptions);
|
||||
const statusTexto = resMail.accepted.length > 0 ? "Enviado" : "Fallido";
|
||||
|
||||
/*
|
||||
|
||||
let status = await this.statusRepository.findOne({ where: { status: statusTexto } });
|
||||
|
||||
|
||||
@@ -117,13 +122,13 @@ export class MailService {
|
||||
destinatario: to,
|
||||
remitente: process.env.USER_GMAIL,
|
||||
|
||||
}); */
|
||||
});
|
||||
|
||||
|
||||
if(!resMail){
|
||||
throw new Error("fallo")
|
||||
}
|
||||
//this.correoRepository.save(info);
|
||||
this.correoRepository.save(info);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { IsString, IsOptional, IsBoolean, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class ComprobarSistemaDto {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
token: string;
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsString, IsOptional, IsBoolean, IsNotEmpty } from 'class-validator';
|
||||
import { IsString, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class CreateSistemaDto {
|
||||
@IsNotEmpty()
|
||||
@@ -9,8 +9,8 @@ export class CreateSistemaDto {
|
||||
@IsString()
|
||||
ip:string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
password: string;
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export class SistemaController {
|
||||
|
||||
@Post()
|
||||
@ApiCreateSistema()
|
||||
create(@Body() createSistemaDto: CreateSistemaDto, password:string) {
|
||||
create(@Body() createSistemaDto: CreateSistemaDto) {
|
||||
return this.sistemaService.create(createSistemaDto);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,6 @@ import { Sistema } from 'src/typeorm/votacionesPrueba.entity';
|
||||
TypeOrmModule.forFeature([
|
||||
Sistema])
|
||||
],
|
||||
exports:[SistemaModule]
|
||||
exports:[SistemaModule,SistemaService]
|
||||
})
|
||||
export class SistemaModule {}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Sistema } from 'src/typeorm/votacionesPrueba.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { randomBytes } from 'crypto';
|
||||
import { ComprobarSistemaDto } from './dto/comprobar-sistema';
|
||||
|
||||
@Injectable()
|
||||
export class SistemaService {
|
||||
@@ -35,6 +36,15 @@ export class SistemaService {
|
||||
return sistema.token;
|
||||
}
|
||||
|
||||
async acceso(TOKEN:string){
|
||||
const result = await this.sistemaRepository.findOne({where:{token:TOKEN}})
|
||||
if(!result){
|
||||
throw new UnauthorizedException('token erroneo')
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
async create(createSistemaDto: CreateSistemaDto) {
|
||||
if(createSistemaDto.password!==process.env.ADMIN_PASSWORD){
|
||||
throw new UnauthorizedException('Password erroneo');
|
||||
|
||||
@@ -13,7 +13,7 @@ export class Sistema {
|
||||
nombre_sistema: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50 })
|
||||
ip:string
|
||||
ip:string;
|
||||
|
||||
@OneToMany(() => Correo, (correo) => correo.id_sistema)
|
||||
correos: Correo[];
|
||||
|
||||
Reference in New Issue
Block a user