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..835da9f 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..910488f 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/eventos/evento.entity.ts b/src/eventos/evento.entity.ts index e4abbcc..4c162d5 100644 --- a/src/eventos/evento.entity.ts +++ b/src/eventos/evento.entity.ts @@ -35,7 +35,7 @@ export class Evento { @Column({ nullable: false }) cupo: number; - @Column({ length: 300, nullable: false }) + @Column({ length: 500, nullable: false }) observaciones: string; @Column({ type: 'decimal', precision: 7, scale: 2, nullable: true }) @@ -47,7 +47,7 @@ export class Evento { @Column({ length: 40, nullable: true }) tipo_acreditacion: string; - @Column({ length: 200, nullable: false }) + @Column({ length: 500, nullable: false }) objetivo: string; @Column({ nullable: false, type: 'datetime' }) diff --git a/src/inscripcion-dsc/inscripcion-dsc.controller.ts b/src/inscripcion-dsc/inscripcion-dsc.controller.ts index d1f7998..817b966 100644 --- a/src/inscripcion-dsc/inscripcion-dsc.controller.ts +++ b/src/inscripcion-dsc/inscripcion-dsc.controller.ts @@ -5,6 +5,7 @@ import { Post, } from '@nestjs/common'; import { InscripcionDscService } from './inscripcion-dsc.service'; +import { And } from 'typeorm'; @Controller('inscripcion-dsc') export class InscripcionDscController { @@ -34,7 +35,7 @@ console.log('Usuario verificacion', userVerification); try{ /* console.log("verificando confirmacion:", userInformation); - */ if (userInformation[0].confirmacion) { + */ if (userInformation[0].confirmacion && userInformation[1].confirmacion) { return { error: true, msj: 'El usuario ya hizo la confirmación anteriormente', diff --git a/src/inscripcion-dsc/inscripcion-dsc.service.ts b/src/inscripcion-dsc/inscripcion-dsc.service.ts index 683fa82..857eef8 100644 --- a/src/inscripcion-dsc/inscripcion-dsc.service.ts +++ b/src/inscripcion-dsc/inscripcion-dsc.service.ts @@ -4,18 +4,21 @@ 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, database: process.env.DB_NAME_DSC, }); - console.log('despues de la conecion a la base') - + // const userInformationQuery = `SELECT A.id_cuenta, nombre, if(AI.platica=true,1,0) as confirmacion FROM alumno A + // JOIN alumno_inscrito AI ON (A.id_cuenta = AI.id_cuenta) + // JOIN periodo P ON (P.id_periodo = AI.id_periodo) + // WHERE A.id_cuenta = "${accountNumber}" and P.activo=true`; const userInformationQuery = `SELECT A.id_cuenta, nombre, if(AI.platica=true,1,0) as confirmacion FROM alumno A - JOIN alumno_inscrito AI ON (A.id_cuenta = AI.id_cuenta) + JOIN alumno_inscrito AI ON (A.id_cuenta = AI.id_cuenta) and (AI.id_plataforma = 1 || AI.id_plataforma = 2) JOIN periodo P ON (P.id_periodo = AI.id_periodo) WHERE A.id_cuenta = "${accountNumber}" and P.activo=true`; @@ -27,12 +30,17 @@ export class InscripcionDscService { const resultsArray = JSON.parse(JSON.stringify(results)); if (resultsArray.length === 0) return null; /* console.log('The solution is: ', resultsArray); */ + console.log('The solution is: ', resultsArray); console.log('Resultados', results) return results; } catch (error) { console.log('Entro al error', error) throw error; + } finally { + if (connection) { + await connection.end(); + } } }