added new Ep

This commit is contained in:
2025-10-08 15:45:21 -06:00
parent 3cdaf3c690
commit 24d2c7bba8
12 changed files with 90 additions and 57 deletions
@@ -16,9 +16,9 @@ export class AlumnoSancionController {
return this.alumnoSancionService.findbyStudent(+id);
}
@Delete()
deleteSancion(){
@Delete(':id_cuenta')
async deleteSancionesAlumno(@Param('id_cuenta') id_cuenta: number) {
return this.alumnoSancionService.removeByStudent(+id_cuenta);
}
}
//IO
//IO
+22 -18
View File
@@ -15,9 +15,7 @@ export class AlumnoSancionService {
private readonly sancionService: SancionService,
) {}
async create(
createAlumnoSancionDto: CreateAlumnoSancionDto,
) {
async create(createAlumnoSancionDto: CreateAlumnoSancionDto) {
const { id_sancion, id_cuenta } = createAlumnoSancionDto;
const alumno = await this.alumnoService.findOne(id_cuenta);
@@ -39,24 +37,30 @@ export class AlumnoSancionService {
async findbyStudent(id_cuenta: number): Promise<AlumnoSancion[]> {
const alusancion = await this.alumnosancionRepository.find({
where: { alumno: { id_cuenta } },
select:{
id_alumno_sancion:true,
fecha_inicio:true,
alumno:{
id_cuenta:true,
nombre:true
},
sancion:{
id_sancion:true,
sancion:true,
duracion:true
}
}
});
if (!alusancion) {
if (alusancion.length === 0) {
throw new NotFoundException(`student without sancion`);
}
return alusancion;
}
async removeByStudent(id_cuenta: number): Promise<{ message: string }> {
const sanciones = await this.alumnosancionRepository.find({
where: { alumno: { id_cuenta } },
});
if (!sanciones || sanciones.length === 0) {
throw new NotFoundException(
`El alumno con id ${id_cuenta} no tiene sanciones`,
);
}
await this.alumnosancionRepository.delete({ alumno: { id_cuenta } });
return {
message: `Todas las sanciones del alumno ${id_cuenta} han sido eliminadas`,
};
}
}
//IO
//IO
@@ -22,7 +22,6 @@ export class AlumnoSancion {
fecha_inicio: Date;
@ManyToOne(() => Alumno, (student) => student.sanciones, {
eager: true,
nullable: false,
})
@JoinColumn({ name: 'id_cuenta' })