diff --git a/src/cuestionario/cuestionario.service.ts b/src/cuestionario/cuestionario.service.ts index 01aad4f..011fb4a 100644 --- a/src/cuestionario/cuestionario.service.ts +++ b/src/cuestionario/cuestionario.service.ts @@ -488,8 +488,6 @@ export class CuestionarioService { }, })); - console.log(opcionesFormateadas); - // Construir objeto de pregunta según el formato requerido return { id_seccion_pregunta: sp.id_seccion_pregunta, @@ -536,6 +534,8 @@ export class CuestionarioService { ? { id_evento: cuestionario.evento.id_evento, nombre_evento: cuestionario.evento.nombre_evento, + descripcion_evento: cuestionario.evento.descripcion_evento, + banner: cuestionario.evento.banner, tipo_evento: cuestionario.evento.tipo_evento, fecha_inicio: cuestionario.evento.fecha_inicio ? cuestionario.evento.fecha_inicio.toISOString() diff --git a/src/cuestionario/docs/cuestionario.examples.ts b/src/cuestionario/docs/cuestionario.examples.ts index 10fb0a7..5bc4214 100644 --- a/src/cuestionario/docs/cuestionario.examples.ts +++ b/src/cuestionario/docs/cuestionario.examples.ts @@ -46,12 +46,13 @@ export const ejemploCuestionarioAlumno = { titulo: 'Apellidos', tipo: 'Abierta (Respuesta corta)', obligatoria: true, - validacion: TiposValidacion.NOMBRE, + validacion: TiposValidacion.APELLIDOS, }, { titulo: 'Género', tipo: 'Cerrada', obligatoria: true, + validacion: TiposValidacion.GENERO, opciones: [ { valor: 'Masculino' }, { valor: 'Femenino' }, @@ -62,11 +63,13 @@ export const ejemploCuestionarioAlumno = { titulo: 'Institución de procedencia', tipo: 'Abierta (Respuesta corta)', obligatoria: true, + validacion: TiposValidacion.INSTITUCION, }, { titulo: 'Carrera', tipo: 'Abierta (Respuesta corta)', obligatoria: true, + validacion: TiposValidacion.CARRERA, }, ], }, diff --git a/src/cuestionario/entities/cuestionario.entity.ts b/src/cuestionario/entities/cuestionario.entity.ts index ca73447..ee2f068 100644 --- a/src/cuestionario/entities/cuestionario.entity.ts +++ b/src/cuestionario/entities/cuestionario.entity.ts @@ -52,7 +52,9 @@ export class Cuestionario { @JoinColumn({ name: 'id_evento' }) evento?: Evento; - @ManyToOne(() => TipoCuestionario, (tipo) => tipo.cuestionarios) + @ManyToOne(() => TipoCuestionario, (tipo) => tipo.cuestionarios, { + eager: true, + }) @JoinColumn({ name: 'id_tipo_cuestionario' }) tipoCuestionario: TipoCuestionario; diff --git a/src/cuestionario_respondido/cuestionario_respondido.service.ts b/src/cuestionario_respondido/cuestionario_respondido.service.ts index e7677e0..f702a1d 100644 --- a/src/cuestionario_respondido/cuestionario_respondido.service.ts +++ b/src/cuestionario_respondido/cuestionario_respondido.service.ts @@ -79,9 +79,11 @@ export class CuestionarioRespondidoService { }, ); if (cuestionarioRespondidoExistente) { - throw new BadRequestException( - `El participante con correo ${submitDto.correo} ya ha respondido el cuestionario ${cuestionario.nombre_form}.`, - ); + await queryRunner.rollbackTransaction(); + return { + success: false, + message: `El participante con correo ${submitDto.correo} ya ha respondido el cuestionario ${cuestionario.nombre_form}.`, + }; } // 3. Crear un nuevo registro de cuestionario respondido @@ -192,8 +194,6 @@ export class CuestionarioRespondidoService { id_cuestionario: number; } | null = null; - console.log(cuestionario.evento); - // Capturamos los datos para el QR if (cuestionario.evento && cuestionario.evento.id_evento) { datosQR = { @@ -412,11 +412,6 @@ export class CuestionarioRespondidoService { [id], ); - console.log( - 'Respuestas cerradas SQL:', - JSON.stringify(respuestasCerradas, null, 2), - ); - // Transformar las respuestas cerradas al formato deseado const respuestasCerradasFormateadas = respuestasCerradas.map( (respuesta) => ({ diff --git a/src/evento/evento.controller.ts b/src/evento/evento.controller.ts index 60cdb66..d77a7a4 100644 --- a/src/evento/evento.controller.ts +++ b/src/evento/evento.controller.ts @@ -35,9 +35,9 @@ export class EventoController { return this.eventoService.getEventos(); } - @Get(':id/cuestionarios') - getCuestionarios(@Param('id', ParseIntPipe) id: number) { - return this.eventoService.getCuestionariosEvento(id); + @Get('activos/cuestionarios') + getCuestionariosActivos() { + return this.eventoService.getEventosActivosCuestionarios(); } @Get('activos') @@ -45,6 +45,19 @@ export class EventoController { return this.eventoService.getEventosActivos(); } + @Get(':id/cuestionarios') + getCuestionarios(@Param('id', ParseIntPipe) id: number) { + return this.eventoService.getCuestionariosEvento(id); + } + + @Get(':id_evento/cuestionario/:id_cuestionario') + getCuestionarioEvento( + @Param('id_evento', ParseIntPipe) id_evento: number, + @Param('id_cuestionario', ParseIntPipe) id_cuestionario: number, + ) { + return this.eventoService.getCuestionarioEvento(id_evento, id_cuestionario); + } + @Post(':id/banner') @UseInterceptors( FileInterceptor('banner', { diff --git a/src/evento/evento.service.ts b/src/evento/evento.service.ts index 47d942f..ea2199d 100644 --- a/src/evento/evento.service.ts +++ b/src/evento/evento.service.ts @@ -69,6 +69,17 @@ export class EventoService { }); } + async getEventosActivosCuestionarios() { + const eventos = await this.eventoRepository.find({ + where: { + fecha_fin: MoreThan(new Date()), + }, + relations: ['cuestionarios'], // solo los cuestionarios, sin secciones + }); + + return eventos; + } + async getEventoOrFail(id_evento: number): Promise { const eventoFound = await this.eventoRepository.findOne({ where: { @@ -113,4 +124,35 @@ export class EventoService { }, }); } + + async getCuestionarioEvento( + id_evento: number, + id_cuestionario: number, + ) { + const evento = await this.eventoRepository.findOne({ + where: { id_evento }, + relations: ['cuestionarios'], + }); + + if (!evento) { + throw new NotFoundException(`Evento con ID ${id_evento} no encontrado.`); + } + + const cuestionario = evento.cuestionarios.find( + (c) => c.id_cuestionario === id_cuestionario, + ); + + if (!cuestionario) { + throw new NotFoundException( + `Cuestionario no asignado al evento ${evento.nombre_evento}.`, + ); + } + + // Return evento info, but only with the searched cuestionario + return { + ...evento, + cuestionarios: undefined, + cuestionario: cuestionario, + }; + } } diff --git a/src/participante_evento/participante_evento.service.ts b/src/participante_evento/participante_evento.service.ts index f7808c5..83b8f74 100644 --- a/src/participante_evento/participante_evento.service.ts +++ b/src/participante_evento/participante_evento.service.ts @@ -90,7 +90,6 @@ export class ParticipanteEventoService { async getParticipantesPorCuestionario(id_cuestionario: number) { const cuestionario = await this.cuestionarioService.getCuestionarioOrFail(id_cuestionario); - console.log(cuestionario); const participantesEvento = await this.participanteEventoRepository.find({ where: { id_cuestionario }, diff --git a/src/pregunta/entities/pregunta.entity.ts b/src/pregunta/entities/pregunta.entity.ts index 15c46a0..8b54cc8 100644 --- a/src/pregunta/entities/pregunta.entity.ts +++ b/src/pregunta/entities/pregunta.entity.ts @@ -16,12 +16,16 @@ export enum TiposValidacion { CORREO_INSTITUCIONAL = 'correo_institucional', TELEFONO = 'telefono', NOMBRE = 'nombre', + APELLIDOS = 'apellidos', ENTERO = 'entero', DECIMAL = 'decimal', COMUNIDAD_ALUMNO = 'comunidad_alumno', CUENTA_ALUMNO = 'cuenta_alumno', COMUNIDAD_TRABAJADOR = 'comunidad_trabajador', CUENTA_TRABAJADOR = 'cuenta_trabajador', + GENERO = 'genero', + CARRERA = 'carrera', + INSTITUCION = 'institucion', } @Entity() diff --git a/uploads/banners/banner-1750103308438-995542211.jpeg b/uploads/banners/banner-1750103308438-995542211.jpeg deleted file mode 100644 index b99380a..0000000 Binary files a/uploads/banners/banner-1750103308438-995542211.jpeg and /dev/null differ diff --git a/uploads/banners/banner-1750103174963-705371719.jpeg b/uploads/banners/banner-1750119255813-528833393.jpeg similarity index 100% rename from uploads/banners/banner-1750103174963-705371719.jpeg rename to uploads/banners/banner-1750119255813-528833393.jpeg