2026-01-27 12:26:22 -06:00
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class BitacoraService {
|
|
|
|
|
constructor(
|
|
|
|
|
@InjectRepository(Bitacora)
|
2026-01-27 13:48:32 -06:00
|
|
|
private readonly bitacoraRepository: Repository<Bitacora>,
|
2026-01-27 12:26:22 -06:00
|
|
|
) {}
|
|
|
|
|
create(createBitacoraDto: CreateBitacoraDto) {
|
|
|
|
|
return 'This action adds a new bitacora';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findAll() {
|
|
|
|
|
return `This action returns all bitacora`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async findOneByAcount(id_cuenta: number) {
|
2026-01-27 13:48:32 -06:00
|
|
|
const student = await this.bitacoraRepository
|
2026-01-27 12:26:22 -06:00
|
|
|
.createQueryBuilder('bitacora')
|
|
|
|
|
.leftJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
|
|
|
|
|
.leftJoinAndSelect('alumnoInscrito.alumno', 'alumno')
|
|
|
|
|
.leftJoinAndSelect('alumno.carrera', 'carrera')
|
|
|
|
|
.leftJoinAndSelect('bitacora.equipo', 'equipo')
|
|
|
|
|
.where('alumno.id_cuenta = :id_cuenta', { id_cuenta })
|
|
|
|
|
|
|
|
|
|
.andWhere(
|
|
|
|
|
`TIMESTAMPDIFF(SECOND,NOW(),DATE_ADD(bitacora.tiempo_entrada, INTERVAL bitacora.tiempo_asignado MINUTE)) > 0`,
|
|
|
|
|
)
|
|
|
|
|
.orderBy('bitacora.tiempo_entrada', 'DESC')
|
|
|
|
|
.getOne();
|
|
|
|
|
|
|
|
|
|
if (!student) {
|
|
|
|
|
throw new NotFoundException('Alumno sin equipo asignado');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return student;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async findOneByMachine(ubicacion: number) {
|
2026-01-27 13:48:32 -06:00
|
|
|
const student = await this.bitacoraRepository
|
2026-01-27 12:26:22 -06:00
|
|
|
.createQueryBuilder('bitacora')
|
|
|
|
|
.leftJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
|
|
|
|
|
.leftJoinAndSelect('alumnoInscrito.alumno', 'alumno')
|
|
|
|
|
.leftJoinAndSelect('alumno.carrera', 'carrera')
|
|
|
|
|
.leftJoinAndSelect('bitacora.equipo', 'equipo')
|
|
|
|
|
.where('equipo.ubicacion = :ubicacion', { ubicacion })
|
|
|
|
|
|
|
|
|
|
.andWhere(
|
|
|
|
|
`TIMESTAMPDIFF(SECOND,NOW(),DATE_ADD(bitacora.tiempo_entrada, INTERVAL bitacora.tiempo_asignado MINUTE)) > 0`,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
.orderBy('bitacora.tiempo_entrada', 'DESC')
|
|
|
|
|
.getOne();
|
|
|
|
|
|
|
|
|
|
if (!student) {
|
|
|
|
|
throw new NotFoundException('Equipo no asignado');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return student;
|
|
|
|
|
}
|
2026-01-27 13:48:32 -06:00
|
|
|
|
|
|
|
|
async cancelation(id_bitacora: number, nuevoTiempo: number) {
|
|
|
|
|
const bitacora = await this.bitacoraRepository.findOne({
|
|
|
|
|
where: { id_bitacora },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!bitacora) {
|
|
|
|
|
throw new NotFoundException('alumno sin equipo asignado');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bitacora.tiempo_asignado -= nuevoTiempo;
|
|
|
|
|
|
|
|
|
|
await this.bitacoraRepository.save(bitacora);
|
|
|
|
|
|
|
|
|
|
return { message: 'Tiempo cancelado' };
|
|
|
|
|
}
|
2026-01-27 12:26:22 -06:00
|
|
|
}
|