From 5567a26ed6b814d0e0fe17c3f4d079529d65df2c Mon Sep 17 00:00:00 2001 From: santiago Date: Wed, 10 Dec 2025 10:59:26 -0600 Subject: [PATCH] Se modificaron varias cosas y se agrego un endpoint nuevo para hacer pruebas --- server/uploads/2023_gustavo_baz_prada.csv | 0 server/uploads/reporte.csv | 3 +-- src/servicio/servicio.controller.ts | 17 ++++++++++++++++ src/servicio/servicio.service.ts | 24 ++++++++++++++++++++++- 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 server/uploads/2023_gustavo_baz_prada.csv diff --git a/server/uploads/2023_gustavo_baz_prada.csv b/server/uploads/2023_gustavo_baz_prada.csv new file mode 100644 index 0000000..e69de29 diff --git a/server/uploads/reporte.csv b/server/uploads/reporte.csv index 69974b3..a271604 100644 --- a/server/uploads/reporte.csv +++ b/server/uploads/reporte.csv @@ -1,3 +1,2 @@ numeroCuenta,nombre,licenciatura,correo,fechaInicio,fechaFin,fechaLiberacion,institucion,dependencia,programa,profesor,clave,status -315040357,RAMIREZ AVILA MELANY BETSABE,LIC. EN HISTORIA,424018289@pcpuma.acatlan.unam.mx,29/7/2024,3/12/2025,"",Instituto Nacional De Antropologia E Historia,Museo Nacional De Antropologia,"Investigación, conservación y difusión del patrimonio arqueológico y etnográfico de México","",2024-21/7-1471,Pre-Termino -319304899,ASCENCIO DIAZ ENRIQUE,LIC. EN ACTUARIA,424018289@pcpuma.acatlan.unam.mx,27/10/2024,1/12/2025,"",UNAM,FES ACATLAN,Acatlán Contigo,Act. Jorge Carmona Mendoza,2025-12/145-24,Cancelado +413076379,JIMENEZ GONZALEZ JAZMIN ALEJANDRA,LIC. EN MATEMATICAS APLICADAS Y COMP.,424018289@pcpuma.acatlan.unam.mx,1/12/2025,4/12/2025,"",UNAM,FES ACATLAN,Acatlán Contigo,xxxx,2025-12/145-24,Pre-Registro diff --git a/src/servicio/servicio.controller.ts b/src/servicio/servicio.controller.ts index 440d223..2696303 100644 --- a/src/servicio/servicio.controller.ts +++ b/src/servicio/servicio.controller.ts @@ -12,6 +12,7 @@ import { Res, ParseIntPipe, Param, + Req, } from '@nestjs/common'; import { FileInterceptor, @@ -30,6 +31,19 @@ export class ServicioController { // ------------------ POST ------------------ + // Garegue un nuevo endpoint para hacer pruebas + @Post('test-upload') + @UseInterceptors(FileInterceptor('file')) + uploadTest( + @UploadedFile() file: Express.Multer.File, + @Req() req: any, + ) { + console.log('FILE:', file); + console.log('FILES REQ:', req.file); + console.log('FILES BODY:', req.body); + return { ok: true }; + } + @Post('nuevo') @UseGuards(AuthGuard('jwt')) @UseInterceptors(FileInterceptor('cartaAceptacion')) @@ -38,6 +52,9 @@ export class ServicioController { @Body('alumno') alumnoJson: string, ) { const dto: CrearServicioDto = JSON.parse(alumnoJson); + + console.log('Archivo recibido:', file); + return await this.servicioService.registrarNuevoServicio(dto, file); } diff --git a/src/servicio/servicio.service.ts b/src/servicio/servicio.service.ts index d198341..727cb0a 100644 --- a/src/servicio/servicio.service.ts +++ b/src/servicio/servicio.service.ts @@ -643,7 +643,29 @@ export class ServicioService { ): Promise<{ message: string }> { // 🔹 Validaciones - const archivoPath = `./server/uploads/${this.validacionService.validacionBasicaStr(file, 'archivo', true, 1000)}`; + // Agregue una validacion para el archivo + if (!file) { + throw new BadRequestException('No se ha proporcionado un archivo.'); + } + + /* Codigo anterior + const archivoPath = `./server/uploads/${this.validacionService.validacionBasicaStr(file.filename, 'archivo', true, 1000)}`; + */ + // Hacemos una validacion en el nombre + const nombreArchivo = `./server/uploads/${this.validacionService.validacionBasicaStr(file.filename, 'archivo', true, 1000)}`; + + const archivoPath = `./server/uploads/${nombreArchivo}`; + + // Validacion de tipo de archivo + if (file.mimetype !== 'application/pdf') { + throw new BadRequestException('La carta debe ser un archivo PDF.'); + } + + // Validacion de tamanio + if (file.size > 5 * 1024 * 1024) { + throw new BadRequestException('La carta debe ser menor a 5MB.'); + } + const progInterno = dto.programaInterno ? this.validacionService.validarAlfanumerico( dto.programaInterno,