Refactor cuestionario service and event handling; update validation types and remove unused console logs; add new event retrieval methods
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
@@ -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', {
|
||||
|
||||
@@ -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<Evento> {
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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()
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
Reference in New Issue
Block a user