new ep findSancion
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<AlumnoSancion>,
|
||||
|
||||
@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<boolean> {
|
||||
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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user