se agregó más documentación
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
import { MailService } from './mail.service';
|
||||
import { ExcelService } from 'src/excel/excel.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { ApiSendMail, ApiSendMailExcel} from './mail.decorators';
|
||||
import { ApiFindAllMails, ApiSendMail, ApiSendMailExcel} from './mail.decorators';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Sistema } from 'src/typeorm/votacionesPrueba.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
@@ -23,7 +23,6 @@ export class MailController {
|
||||
constructor(
|
||||
private readonly mailService: MailService,
|
||||
private readonly excelService: ExcelService,
|
||||
private readonly sistemaService: SistemaService,
|
||||
@InjectRepository(Sistema) private readonly sistemaRepository: Repository<Sistema>,
|
||||
|
||||
) {}
|
||||
@@ -92,7 +91,9 @@ export class MailController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll(){
|
||||
return await this.mailService.findAll()
|
||||
@ApiFindAllMails()
|
||||
async findAll(@Headers() headers:{token:string}){
|
||||
|
||||
return await this.mailService.findAll(headers.token)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { applyDecorators } from '@nestjs/common';
|
||||
import { ApiBody, ApiConsumes, ApiHeader, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||||
import { ApiBody, ApiConsumes, ApiHeader, ApiOperation, ApiResponse, ApiUnauthorizedResponse } from '@nestjs/swagger';
|
||||
|
||||
export const ApiSendMail = () => {
|
||||
return applyDecorators(
|
||||
@@ -122,3 +122,38 @@ El archivo debe contener una columna con direcciones de correo válidas.`,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
export const ApiFindAllMails = () => {
|
||||
return applyDecorators(
|
||||
ApiOperation({
|
||||
summary: 'Obtener todos los correos enviados',
|
||||
description: `Este endpoint retorna la lista de todos los correos enviados por el sistema autenticado mediante el token proporcionado.`,
|
||||
}),
|
||||
ApiHeader({
|
||||
name: 'token',
|
||||
description: 'Contraseña del sistema para autenticación',
|
||||
required: true,
|
||||
example: 'mi-password-segura',
|
||||
}),
|
||||
ApiResponse({
|
||||
status: 200,
|
||||
description: 'Lista de correos enviados',
|
||||
schema: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'number', example: 1 },
|
||||
destinatario: { type: 'string', example: 'usuario@example.com' },
|
||||
remitente: { type: 'string', example: 'miemail@gmail.com' },
|
||||
fecha_enviado: { type: 'string', format: 'date-time', example: '2025-04-23T14:30:00Z' },
|
||||
fecha_recibido: { type: 'string', format: 'date-time', example: '2025-04-23T14:00:00Z' },
|
||||
status: { type: 'string', example: 'Enviado' },
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
ApiUnauthorizedResponse({ description: 'Token inválido o no autorizado' })
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import * as nodemailer from 'nodemailer';
|
||||
import * as dotenv from 'dotenv';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
@@ -14,6 +14,7 @@ export class MailService {
|
||||
constructor(
|
||||
@InjectRepository(Correo) private readonly correoRepository: Repository<Correo>,
|
||||
@InjectRepository(Status) private readonly statusRepository: Repository<Status>,
|
||||
@InjectRepository(Sistema) private readonly sistemaRepository: Repository<Sistema>
|
||||
|
||||
) {
|
||||
|
||||
@@ -55,9 +56,20 @@ 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']})
|
||||
|
||||
async findAll(TOKEN:string){
|
||||
if (!TOKEN) {
|
||||
throw new UnauthorizedException('Header "Password" es requerido');
|
||||
}
|
||||
|
||||
const sistem = await this.sistemaRepository.findOne({ where: { token:TOKEN } });
|
||||
|
||||
if (!sistem) {
|
||||
throw new UnauthorizedException('Password incorrecto');
|
||||
}
|
||||
|
||||
|
||||
const result= await this.correoRepository.find()
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user