new ep findSancion
This commit is contained in:
@@ -9,10 +9,10 @@ import { Role } from 'src/role.enum';
|
|||||||
|
|
||||||
@Controller('student')
|
@Controller('student')
|
||||||
export class AlumnoController {
|
export class AlumnoController {
|
||||||
constructor(private readonly alumnoService: AlumnoService) {}
|
constructor(private readonly alumnoService: AlumnoService) { }
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async find(){
|
async find() {
|
||||||
return this.alumnoService.findAll()
|
return this.alumnoService.findAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +23,12 @@ export class AlumnoController {
|
|||||||
|
|
||||||
//@UseGuards(JwtAuthGuard)
|
//@UseGuards(JwtAuthGuard)
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
findOneWhitSancion(@Param('id') id: number) {
|
||||||
|
return this.alumnoService.findOneWhitSancion(+id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//@UseGuards(JwtAuthGuard)
|
||||||
|
@Get('sancion/:id')
|
||||||
findOne(@Param('id') id: number) {
|
findOne(@Param('id') id: number) {
|
||||||
return this.alumnoService.findOne(+id);
|
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 { AlumnoService } from './student.service';
|
||||||
import { AlumnoController } from './student.controller';
|
import { AlumnoController } from './student.controller';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Alumno } from './entities/student.entity';
|
import { Alumno } from './entities/student.entity';
|
||||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||||
|
import { AlumnoSancionModule } from 'src/alumno_sancion/alumno_sancion.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([Alumno, Carrera])],
|
imports: [TypeOrmModule.forFeature([Alumno, Carrera]),
|
||||||
|
forwardRef(() => AlumnoSancionModule),
|
||||||
|
],
|
||||||
controllers: [AlumnoController],
|
controllers: [AlumnoController],
|
||||||
providers: [AlumnoService],
|
providers: [AlumnoService],
|
||||||
exports: [AlumnoService],
|
exports: [AlumnoService],
|
||||||
})
|
})
|
||||||
export class AlumnoModule {}
|
export class AlumnoModule { }
|
||||||
//IO
|
//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 { CreateStudentDto } from './dto/create-student.dto';
|
||||||
import { Alumno } from './entities/student.entity';
|
import { Alumno } from './entities/student.entity';
|
||||||
import { EntityManager, Repository } from 'typeorm';
|
import { EntityManager, Repository } from 'typeorm';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
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()
|
@Injectable()
|
||||||
export class AlumnoService {
|
export class AlumnoService {
|
||||||
@@ -12,7 +14,10 @@ export class AlumnoService {
|
|||||||
private readonly studentRepository: Repository<Alumno>,
|
private readonly studentRepository: Repository<Alumno>,
|
||||||
@InjectRepository(Carrera)
|
@InjectRepository(Carrera)
|
||||||
private readonly carreraRepository: Repository<Carrera>,
|
private readonly carreraRepository: Repository<Carrera>,
|
||||||
) {}
|
|
||||||
|
@Inject(forwardRef(() => AlumnoSancionService))
|
||||||
|
private readonly alumnoSancionService: AlumnoSancionService,
|
||||||
|
) { }
|
||||||
|
|
||||||
async findAll(): Promise<Alumno[]> {
|
async findAll(): Promise<Alumno[]> {
|
||||||
return this.studentRepository.find({
|
return this.studentRepository.find({
|
||||||
@@ -22,12 +27,21 @@ export class AlumnoService {
|
|||||||
|
|
||||||
async create(data: CreateStudentDto): Promise<Alumno> {
|
async create(data: CreateStudentDto): Promise<Alumno> {
|
||||||
const { id_carrera, ...rest } = data;
|
const { id_carrera, ...rest } = data;
|
||||||
|
|
||||||
const carrera = await this.carreraRepository.findOne({
|
const carrera = await this.carreraRepository.findOne({
|
||||||
where: { id_carrera: data.id_carrera },
|
where: { id_carrera: data.id_carrera },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!carrera) {
|
if (!carrera) {
|
||||||
throw new NotFoundException(`Carrera not found`);
|
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 createStudent = { ...rest, carrera, fecha_registro: new Date() };
|
||||||
|
|
||||||
const student = this.studentRepository.create(createStudent);
|
const student = this.studentRepository.create(createStudent);
|
||||||
@@ -47,6 +61,24 @@ export class AlumnoService {
|
|||||||
return student;
|
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> {
|
async findOneByName(nombre: string): Promise<Alumno> {
|
||||||
const student = await this.studentRepository.findOne({
|
const student = await this.studentRepository.findOne({
|
||||||
where: { nombre },
|
where: { nombre },
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { forwardRef, Module } from '@nestjs/common';
|
||||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||||
import { AlumnoSancionController } from './alumno_sancion.controller';
|
import { AlumnoSancionController } from './alumno_sancion.controller';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
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 { Sancion } from 'src/sancion/entities/sancion.entity';
|
||||||
import { AlumnoModule } from 'src/alumno/student.module';
|
import { AlumnoModule } from 'src/alumno/student.module';
|
||||||
import { SancionModule } from 'src/sancion/sancion.module';
|
import { SancionModule } from 'src/sancion/sancion.module';
|
||||||
import { AlumnoService } from 'src/alumno/student.service';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([AlumnoSancion, Alumno, Sancion]),
|
TypeOrmModule.forFeature([AlumnoSancion, Alumno, Sancion]),
|
||||||
AlumnoModule,
|
forwardRef(() => AlumnoModule),
|
||||||
SancionModule,
|
SancionModule,
|
||||||
],
|
],
|
||||||
controllers: [AlumnoSancionController],
|
controllers: [AlumnoSancionController],
|
||||||
providers: [AlumnoSancionService],
|
providers: [AlumnoSancionService],
|
||||||
|
exports: [AlumnoSancionService]
|
||||||
})
|
})
|
||||||
export class AlumnoSancionModule {}
|
export class AlumnoSancionModule {}
|
||||||
//IO
|
//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 { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
@@ -11,9 +11,12 @@ export class AlumnoSancionService {
|
|||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(AlumnoSancion)
|
@InjectRepository(AlumnoSancion)
|
||||||
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
||||||
|
|
||||||
|
@Inject(forwardRef(() => AlumnoService))
|
||||||
private readonly alumnoService: AlumnoService,
|
private readonly alumnoService: AlumnoService,
|
||||||
|
|
||||||
private readonly sancionService: SancionService,
|
private readonly sancionService: SancionService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
async create(createAlumnoSancionDto: CreateAlumnoSancionDto) {
|
async create(createAlumnoSancionDto: CreateAlumnoSancionDto) {
|
||||||
const { id_sancion, id_cuenta } = createAlumnoSancionDto;
|
const { id_sancion, id_cuenta } = createAlumnoSancionDto;
|
||||||
@@ -34,6 +37,18 @@ export class AlumnoSancionService {
|
|||||||
return await this.alumnosancionRepository.save(alumnosancion);
|
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) {
|
async findbyStudent(id_cuenta: number) {
|
||||||
const student = await this.alumnoService.findOne(id_cuenta);
|
const student = await this.alumnoService.findOne(id_cuenta);
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export class BitacoraMesaService {
|
|||||||
return this.bitacoraMesaRepository.find({
|
return this.bitacoraMesaRepository.find({
|
||||||
relations: ['mesa', 'alumno_inscrito'],
|
relations: ['mesa', 'alumno_inscrito'],
|
||||||
take: 100,
|
take: 100,
|
||||||
order:{id_bitacora_mesa:"DESC"}
|
order: { id_bitacora_mesa: "DESC" }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ export class BitacoraMesaService {
|
|||||||
.getOne();
|
.getOne();
|
||||||
|
|
||||||
if (!student) {
|
if (!student) {
|
||||||
throw new NotFoundException('alumno sin mesa');
|
throw new NotFoundException('Alumno sin mesa');
|
||||||
}
|
}
|
||||||
|
|
||||||
return student;
|
return student;
|
||||||
|
|||||||
Reference in New Issue
Block a user