From 99f76c9412b30f76e62c970f3746bc0232cf4d50 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Thu, 19 Feb 2026 15:24:53 -0600 Subject: [PATCH] new ep findSancion --- src/alumno/student.controller.ts | 10 ++++-- src/alumno/student.module.ts | 9 +++-- src/alumno/student.service.ts | 36 ++++++++++++++++++-- src/alumno_sancion/alumno_sancion.module.ts | 6 ++-- src/alumno_sancion/alumno_sancion.service.ts | 19 +++++++++-- src/bitacora_mesa/bitacora_mesa.service.ts | 4 +-- 6 files changed, 70 insertions(+), 14 deletions(-) diff --git a/src/alumno/student.controller.ts b/src/alumno/student.controller.ts index 74ef94c..3db9341 100644 --- a/src/alumno/student.controller.ts +++ b/src/alumno/student.controller.ts @@ -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); } diff --git a/src/alumno/student.module.ts b/src/alumno/student.module.ts index 6e5195a..358caff 100644 --- a/src/alumno/student.module.ts +++ b/src/alumno/student.module.ts @@ -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 diff --git a/src/alumno/student.service.ts b/src/alumno/student.service.ts index c106f24..110a470 100644 --- a/src/alumno/student.service.ts +++ b/src/alumno/student.service.ts @@ -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, @InjectRepository(Carrera) private readonly carreraRepository: Repository, - ) {} + + @Inject(forwardRef(() => AlumnoSancionService)) + private readonly alumnoSancionService: AlumnoSancionService, + ) { } async findAll(): Promise { return this.studentRepository.find({ @@ -22,12 +27,21 @@ export class AlumnoService { async create(data: CreateStudentDto): Promise { 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 { + 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 { const student = await this.studentRepository.findOne({ where: { nombre }, diff --git a/src/alumno_sancion/alumno_sancion.module.ts b/src/alumno_sancion/alumno_sancion.module.ts index 9059330..374c113 100644 --- a/src/alumno_sancion/alumno_sancion.module.ts +++ b/src/alumno_sancion/alumno_sancion.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +import { forwardRef, Module } from '@nestjs/common'; import { AlumnoSancionService } from './alumno_sancion.service'; import { AlumnoSancionController } from './alumno_sancion.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; @@ -7,16 +7,16 @@ import { Alumno } from 'src/alumno/entities/student.entity'; import { Sancion } from 'src/sancion/entities/sancion.entity'; import { AlumnoModule } from 'src/alumno/student.module'; import { SancionModule } from 'src/sancion/sancion.module'; -import { AlumnoService } from 'src/alumno/student.service'; @Module({ imports: [ TypeOrmModule.forFeature([AlumnoSancion, Alumno, Sancion]), - AlumnoModule, + forwardRef(() => AlumnoModule), SancionModule, ], controllers: [AlumnoSancionController], providers: [AlumnoSancionService], + exports: [AlumnoSancionService] }) export class AlumnoSancionModule {} //IO diff --git a/src/alumno_sancion/alumno_sancion.service.ts b/src/alumno_sancion/alumno_sancion.service.ts index 91c61c5..b7f2cd1 100644 --- a/src/alumno_sancion/alumno_sancion.service.ts +++ b/src/alumno_sancion/alumno_sancion.service.ts @@ -1,4 +1,4 @@ -import { Injectable, NotFoundException } from '@nestjs/common'; +import { forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { AlumnoSancion } from './entities/alumno_sancion.entity'; import { Repository } from 'typeorm'; @@ -11,9 +11,12 @@ export class AlumnoSancionService { constructor( @InjectRepository(AlumnoSancion) private readonly alumnosancionRepository: Repository, + + @Inject(forwardRef(() => AlumnoService)) private readonly alumnoService: AlumnoService, + private readonly sancionService: SancionService, - ) {} + ) { } async create(createAlumnoSancionDto: CreateAlumnoSancionDto) { const { id_sancion, id_cuenta } = createAlumnoSancionDto; @@ -34,6 +37,18 @@ export class AlumnoSancionService { return await this.alumnosancionRepository.save(alumnosancion); } + async findSancion(id_cuenta: number): Promise { + const alusancion = await this.alumnosancionRepository.find({ + where: { alumno: { id_cuenta } }, + }); + + if (alusancion.length === 0) { + return false; + } + + return true; + } + async findbyStudent(id_cuenta: number) { const student = await this.alumnoService.findOne(id_cuenta); diff --git a/src/bitacora_mesa/bitacora_mesa.service.ts b/src/bitacora_mesa/bitacora_mesa.service.ts index ac8477c..c65ef86 100644 --- a/src/bitacora_mesa/bitacora_mesa.service.ts +++ b/src/bitacora_mesa/bitacora_mesa.service.ts @@ -51,7 +51,7 @@ export class BitacoraMesaService { return this.bitacoraMesaRepository.find({ relations: ['mesa', 'alumno_inscrito'], take: 100, - order:{id_bitacora_mesa:"DESC"} + order: { id_bitacora_mesa: "DESC" } }); } @@ -76,7 +76,7 @@ export class BitacoraMesaService { .getOne(); if (!student) { - throw new NotFoundException('alumno sin mesa'); + throw new NotFoundException('Alumno sin mesa'); } return student;