new Ep
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
} from '@nestjs/common';
|
||||
import { EquipoService } from './equipo.service';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
|
||||
@@ -7,13 +15,18 @@ export class EquipoController {
|
||||
constructor(private readonly equipoService: EquipoService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
findAll(): Promise<Equipo[]> {
|
||||
return this.equipoService.findAll();
|
||||
}
|
||||
|
||||
@Get('/student/:id')
|
||||
findOnlyUsable(@Param('id')id:number): Promise<Equipo[]> {
|
||||
return this.equipoService.findOnlyUsable(+id);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: number):Promise<Equipo> {
|
||||
findOne(@Param('id') id: number): Promise<Equipo> {
|
||||
return this.equipoService.findOne(+id);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
@@ -2,22 +2,49 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
import { AlumnoInscritoService } from 'src/alumno_inscrito/alumno_inscrito.service';
|
||||
|
||||
@Injectable()
|
||||
export class EquipoService {
|
||||
constructor(@InjectRepository(Equipo)
|
||||
private readonly equipoRepository: Repository<Equipo>){}
|
||||
constructor(
|
||||
@InjectRepository(Equipo)
|
||||
private readonly equipoRepository: Repository<Equipo>,
|
||||
// private readonly alumnoInscritoService: AlumnoInscritoService,
|
||||
) {}
|
||||
|
||||
findAll() {
|
||||
return this.equipoRepository.find({relations:['areaUbicacion','plataforma']});
|
||||
return this.equipoRepository.find({
|
||||
relations: ['areaUbicacion', 'plataforma'],
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id_equipo: number):Promise<Equipo> {
|
||||
const equipo = await this.equipoRepository.findOne({where:{id_equipo}})
|
||||
if(!equipo){
|
||||
throw new NotFoundException("not found");
|
||||
async findOne(id_equipo: number): Promise<Equipo> {
|
||||
const equipo = await this.equipoRepository.findOne({
|
||||
where: { id_equipo },
|
||||
});
|
||||
if (!equipo) {
|
||||
throw new NotFoundException('not found');
|
||||
}
|
||||
return equipo;
|
||||
}
|
||||
|
||||
async findOnlyUsable(id_cuenta: number): Promise<Equipo[]> {
|
||||
const equipos = await this.equipoRepository
|
||||
.createQueryBuilder('equipo')
|
||||
.innerJoinAndSelect('equipo.plataforma', 'plataforma')
|
||||
.innerJoin('plataforma.alumnos_inscritos', 'ai')
|
||||
.innerJoin('ai.alumno', 'alumno')
|
||||
.innerJoin('ai.periodo', 'periodo')
|
||||
.where('alumno.id_cuenta = :id_cuenta', { id_cuenta })
|
||||
.andWhere("periodo.activo = b'1'")
|
||||
.andWhere("equipo.activo = b'1'")
|
||||
.getMany();
|
||||
|
||||
if (equipos.length === 0) {
|
||||
throw new NotFoundException('No usable equipment found');
|
||||
}
|
||||
|
||||
return equipos;
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
Reference in New Issue
Block a user