assign machine
This commit is contained in:
@@ -7,8 +7,8 @@ export class BitacoraController {
|
||||
constructor(private readonly bitacoraService: BitacoraService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createBitacoraDto: CreateBitacoraDto) {
|
||||
return this.bitacoraService.create(createBitacoraDto);
|
||||
assignment(@Body() createBitacoraDto: CreateBitacoraDto) {
|
||||
return this.bitacoraService.assignment(createBitacoraDto);
|
||||
}
|
||||
|
||||
@Get('/cuenta/:id')
|
||||
@@ -28,9 +28,9 @@ export class BitacoraController {
|
||||
) {
|
||||
return this.bitacoraService.cancelation(id, tiempo_asignado);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findAll(@Param('id') id: string) {
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.bitacoraService.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateBitacoraDto } from './dto/create-bitacora.dto';
|
||||
import { UpdateBitacoraDto } from './dto/update-bitacora.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Bitacora } from './entities/bitacora.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -11,12 +10,25 @@ export class BitacoraService {
|
||||
@InjectRepository(Bitacora)
|
||||
private readonly bitacoraRepository: Repository<Bitacora>,
|
||||
) {}
|
||||
create(createBitacoraDto: CreateBitacoraDto) {
|
||||
return 'This action adds a new bitacora';
|
||||
|
||||
assignment(dto: CreateBitacoraDto) {
|
||||
const bitacora = this.bitacoraRepository.create({
|
||||
tiempo_entrada: new Date(),
|
||||
tiempo_asignado: dto.tiempo_asignado,
|
||||
ubicacion: dto.ubicacion,
|
||||
equipo: { id_equipo: dto.id_equipo },
|
||||
alumno_inscrito: { id_alumno_inscrito: dto.id_alumno_inscrito },
|
||||
});
|
||||
|
||||
return this.bitacoraRepository.save(bitacora);
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all bitacora`;
|
||||
return this.bitacoraRepository.find({
|
||||
take: 100,
|
||||
order: { tiempo_entrada: 'DESC' },
|
||||
relations: ['alumno_inscrito', 'equipo'],
|
||||
});
|
||||
}
|
||||
|
||||
async findOneByAcount(id_cuenta: number) {
|
||||
@@ -35,7 +47,7 @@ export class BitacoraService {
|
||||
.getOne();
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException('Alumno sin equipo asignado');
|
||||
throw new NotFoundException('No cuenta con tiempo asignado');
|
||||
}
|
||||
|
||||
return student;
|
||||
|
||||
@@ -1 +1,16 @@
|
||||
export class CreateBitacoraDto {}
|
||||
import { IsInt, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreateBitacoraDto {
|
||||
@IsInt()
|
||||
tiempo_asignado: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
ubicacion?: string;
|
||||
|
||||
@IsInt()
|
||||
id_equipo: number;
|
||||
|
||||
@IsInt()
|
||||
id_alumno_inscrito: number;
|
||||
}
|
||||
@@ -19,8 +19,8 @@ export class Bitacora {
|
||||
@Column({ name: 'tiempo_asignado', type: 'int' })
|
||||
tiempo_asignado: number;
|
||||
|
||||
@Column({ name: 'ubicacion', type: 'smallint', nullable: true })
|
||||
ubicacion: number;
|
||||
@Column({ name: 'ubicacion', nullable: true })
|
||||
ubicacion: string;
|
||||
|
||||
@Column({
|
||||
name: 'fecha_actualizacion',
|
||||
@@ -42,7 +42,7 @@ export class Bitacora {
|
||||
{
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
},
|
||||
}
|
||||
)
|
||||
@JoinColumn({ name: 'id_alumno_inscrito' })
|
||||
alumno_inscrito: AlumnoInscrito;
|
||||
|
||||
@@ -53,14 +53,39 @@ export class EquipoService {
|
||||
.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'")
|
||||
.innerJoin('equipo.areaUbicacion', 'area')
|
||||
.where('ai.id_cuenta = :id_cuenta', { id_cuenta })
|
||||
.andWhere('periodo.activo = true')
|
||||
|
||||
.andWhere('equipo.activo = true')
|
||||
|
||||
.andWhere('ai.tiempo_disponible > 0')
|
||||
|
||||
.andWhere('area.extra = 0')
|
||||
|
||||
.andWhere((qb) => {
|
||||
const subQuery = qb
|
||||
.subQuery()
|
||||
.select('bitacora.id_equipo')
|
||||
.from('bitacora', 'bitacora')
|
||||
.where(
|
||||
`TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bitacora.tiempo_entrada, INTERVAL bitacora.tiempo_asignado MINUTE)
|
||||
) > 0`,
|
||||
)
|
||||
.getQuery();
|
||||
|
||||
return `equipo.id_equipo NOT IN ${subQuery}`;
|
||||
})
|
||||
|
||||
.orderBy('equipo.ubicacion', 'ASC')
|
||||
|
||||
.getMany();
|
||||
|
||||
if (equipos.length === 0) {
|
||||
if (!equipos.length) {
|
||||
throw new NotFoundException('No usable equipment found');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user