Refactor cuestionario service and event handling; update validation types and remove unused console logs; add new event retrieval methods

This commit is contained in:
miguel
2025-06-16 18:24:56 -06:00
parent 5f302df2a7
commit d188d8bea3
10 changed files with 76 additions and 18 deletions
+42
View File
@@ -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,
};
}
}