Se implemento el cierre de la conexion en la base de datos

This commit is contained in:
Patriots01
2026-02-07 00:40:01 +00:00
parent 6238c82296
commit fb31589c78
7 changed files with 60 additions and 3 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

+1 -1
View File
@@ -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,
+9
View File
@@ -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);
+35
View File
@@ -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({
+5 -1
View File
@@ -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
}
+4
View File
@@ -12,4 +12,8 @@ export class Carrusel {
@Column({length: 150})
link: string
/* "https://www.acatlan.unam.mx/" */
@Column({length: 20})
orden: string
}
@@ -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();
}
}
}