Refactor cuestionario service and event handling; update validation types and remove unused console logs; add new event retrieval methods
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user