new ep findSancion

This commit is contained in:
2026-02-19 15:24:53 -06:00
parent 8a82b49a5c
commit 99f76c9412
6 changed files with 70 additions and 14 deletions
+8 -2
View File
@@ -9,10 +9,10 @@ import { Role } from 'src/role.enum';
@Controller('student')
export class AlumnoController {
constructor(private readonly alumnoService: AlumnoService) {}
constructor(private readonly alumnoService: AlumnoService) { }
@Get()
async find(){
async find() {
return this.alumnoService.findAll()
}
@@ -23,6 +23,12 @@ export class AlumnoController {
//@UseGuards(JwtAuthGuard)
@Get(':id')
findOneWhitSancion(@Param('id') id: number) {
return this.alumnoService.findOneWhitSancion(+id);
}
//@UseGuards(JwtAuthGuard)
@Get('sancion/:id')
findOne(@Param('id') id: number) {
return this.alumnoService.findOne(+id);
}
+6 -3
View File
@@ -1,15 +1,18 @@
import { Module } from '@nestjs/common';
import { forwardRef, Module } from '@nestjs/common';
import { AlumnoService } from './student.service';
import { AlumnoController } from './student.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Alumno } from './entities/student.entity';
import { Carrera } from 'src/carrera/entities/carrera.entity';
import { AlumnoSancionModule } from 'src/alumno_sancion/alumno_sancion.module';
@Module({
imports: [TypeOrmModule.forFeature([Alumno, Carrera])],
imports: [TypeOrmModule.forFeature([Alumno, Carrera]),
forwardRef(() => AlumnoSancionModule),
],
controllers: [AlumnoController],
providers: [AlumnoService],
exports: [AlumnoService],
})
export class AlumnoModule {}
export class AlumnoModule { }
//IO
+34 -2
View File
@@ -1,9 +1,11 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { ConflictException, forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common';
import { CreateStudentDto } from './dto/create-student.dto';
import { Alumno } from './entities/student.entity';
import { EntityManager, Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Carrera } from 'src/carrera/entities/carrera.entity';
import { AlumnoSancionService } from 'src/alumno_sancion/alumno_sancion.service';
import { ExceptionsHandler } from '@nestjs/core/exceptions/exceptions-handler';
@Injectable()
export class AlumnoService {
@@ -12,7 +14,10 @@ export class AlumnoService {
private readonly studentRepository: Repository<Alumno>,
@InjectRepository(Carrera)
private readonly carreraRepository: Repository<Carrera>,
) {}
@Inject(forwardRef(() => AlumnoSancionService))
private readonly alumnoSancionService: AlumnoSancionService,
) { }
async findAll(): Promise<Alumno[]> {
return this.studentRepository.find({
@@ -22,12 +27,21 @@ export class AlumnoService {
async create(data: CreateStudentDto): Promise<Alumno> {
const { id_carrera, ...rest } = data;
const carrera = await this.carreraRepository.findOne({
where: { id_carrera: data.id_carrera },
});
if (!carrera) {
throw new NotFoundException(`Carrera not found`);
}
const currenStudent = await this.studentRepository.findOne({where:{id_cuenta:data.id_cuenta}})
if(currenStudent){
throw new ConflictException('El usuario ya existe')
}
const createStudent = { ...rest, carrera, fecha_registro: new Date() };
const student = this.studentRepository.create(createStudent);
@@ -47,6 +61,24 @@ export class AlumnoService {
return student;
}
async findOneWhitSancion(id_cuenta: number): Promise<Alumno> {
const student = await this.studentRepository.findOne({
where: { id_cuenta },
select: { id_cuenta: true, nombre: true, credito: true },
});
if (!student) {
throw new NotFoundException(`Numero de cuenta ${id_cuenta} no existente`);
}
const sancion = await this.alumnoSancionService.findSancion(id_cuenta)
if (sancion) {
throw new NotFoundException('El usuario se encuentra sancionado')
}
return student;
}
async findOneByName(nombre: string): Promise<Alumno> {
const student = await this.studentRepository.findOne({
where: { nombre },