2026-01-27 12:26:22 -06:00
|
|
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
|
|
|
import { CreateBitacoraDto } from './dto/create-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
|
|
|
) {}
|
2026-01-27 16:12:23 -06:00
|
|
|
|
|
|
|
|
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);
|
2026-01-27 12:26:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findAll() {
|
2026-01-27 16:12:23 -06:00
|
|
|
return this.bitacoraRepository.find({
|
|
|
|
|
take: 100,
|
|
|
|
|
order: { tiempo_entrada: 'DESC' },
|
|
|
|
|
relations: ['alumno_inscrito', 'equipo'],
|
|
|
|
|
});
|
2026-01-27 12:26:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
2026-01-27 16:12:23 -06:00
|
|
|
throw new NotFoundException('No cuenta con tiempo asignado');
|
2026-01-27 12:26:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|