diff --git a/public/carrusel/carrusel1.jpg b/public/carrusel/carrusel1.jpg new file mode 100644 index 0000000..1a1ba10 Binary files /dev/null and b/public/carrusel/carrusel1.jpg differ diff --git a/src/app.module.ts b/src/app.module.ts index 83aaa83..4e4e5a5 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -75,7 +75,7 @@ import { Almacenamiento } from './almacenamiento/entity/almacenamiento.entity'; username: configService.get('DB_USER'), password: configService.get('DB_PASSWORD'), database: configService.get('DB_NAME'), - synchronize: true, + synchronize: false, entities: [ Evento, Participante, diff --git a/src/carrusel/carrusel.controller.ts b/src/carrusel/carrusel.controller.ts index d7102ca..b03949b 100644 --- a/src/carrusel/carrusel.controller.ts +++ b/src/carrusel/carrusel.controller.ts @@ -5,6 +5,7 @@ import { Get, Param, ParseIntPipe, + Patch, Post, Res, UploadedFile, @@ -48,6 +49,14 @@ export class CarruselController { return this.carruselService.addImagenToCarrusel(carruselDto, file.filename); } + @Patch('update/:id') + updateImagenCarrusel( + @Param('id', ParseIntPipe) id: number, + @Body() carruselDto: carruselDto, + ) { + return this.carruselService.updateImagenCarrusel(id, carruselDto); + } + @Delete('delete/:id') deleteImagenByRuta(@Param('id', ParseIntPipe) id: number) { return this.carruselService.deleteImagenByRuta(id); diff --git a/src/carrusel/carrusel.service.ts b/src/carrusel/carrusel.service.ts index 93404ba..18bf892 100644 --- a/src/carrusel/carrusel.service.ts +++ b/src/carrusel/carrusel.service.ts @@ -60,6 +60,41 @@ export class CarruselService { }); } } + async updateImagenCarrusel( + id: number, + carruselDto: carruselDto, + ): Promise<{ message: string; carrusel: Carrusel }> { + const carrusel = await this.carruselRepository.findOne({ + where: { id_imagen_carrusel: id }, + }); + + if (!carrusel) { + throw new BadRequestException({ + message: `No se encontró una imagen de carrusel con el id ${id}`, + }); + } + + Object.assign(carrusel, carruselDto); + + try { + const carruselUpdated = await this.carruselRepository.save(carrusel); + return { + message: 'Imagen de carrusel actualizada correctamente', + carrusel: carruselUpdated, + }; + } catch (error) { + console.error('❌ Error al actualizar carrusel en base de datos'); + console.table({ + code: error.code, + message: error.message, + }); + + throw new InternalServerErrorException({ + message: 'Ocurrió un error inesperado al actualizar la imagen', + error: error.message, + }); + } + } async deleteImagenByRuta(id: number) { try { const res = await this.carruselRepository.findOne({ diff --git a/src/carrusel/dto/carruselDto.dto.ts b/src/carrusel/dto/carruselDto.dto.ts index e0ff309..c1b1d78 100644 --- a/src/carrusel/dto/carruselDto.dto.ts +++ b/src/carrusel/dto/carruselDto.dto.ts @@ -1,4 +1,4 @@ -import { IsNotEmpty } from "class-validator"; +import { IsNotEmpty, IsOptional } from "class-validator"; export class carruselDto { @IsNotEmpty() @@ -6,4 +6,8 @@ export class carruselDto { @IsNotEmpty() link: string + + // @IsNotEmpty() valida que no sea nulo ni undefined ni cadena vacía + @IsOptional() + orden?: string } \ No newline at end of file diff --git a/src/carrusel/entity/carrusel.entity.ts b/src/carrusel/entity/carrusel.entity.ts index e6646b8..4a1613f 100644 --- a/src/carrusel/entity/carrusel.entity.ts +++ b/src/carrusel/entity/carrusel.entity.ts @@ -12,4 +12,8 @@ export class Carrusel { @Column({length: 150}) link: string /* "https://www.acatlan.unam.mx/" */ + + @Column({length: 20}) + orden: string + } \ No newline at end of file diff --git a/src/inscripcion-dsc/inscripcion-dsc.service.ts b/src/inscripcion-dsc/inscripcion-dsc.service.ts index 9cd9501..0d33b02 100644 --- a/src/inscripcion-dsc/inscripcion-dsc.service.ts +++ b/src/inscripcion-dsc/inscripcion-dsc.service.ts @@ -4,8 +4,9 @@ import { createConnection } from 'mysql2/promise'; @Injectable() export class InscripcionDscService { async userVerification(accountNumber: string) { + let connection; try { - const connection = await createConnection({ + connection = await createConnection({ host: process.env.DB_HOST_DSC, user: process.env.DB_USER_DSC, password: process.env.DB_PASS_DSC, @@ -32,6 +33,10 @@ export class InscripcionDscService { return results; } catch (error) { throw error; + } finally { + if (connection) { + await connection.end(); + } } }