added Lino
This commit is contained in:
@@ -3,6 +3,8 @@ import { CreateBitacoraMesaDto } from './dto/create-bitacora_mesa.dto';
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { BitacoraMesa } from './entities/bitacora_mesa.entity';
|
import { BitacoraMesa } from './entities/bitacora_mesa.entity';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import { BadRequestException } from '@nestjs/common';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BitacoraMesaService {
|
export class BitacoraMesaService {
|
||||||
@@ -11,17 +13,40 @@ export class BitacoraMesaService {
|
|||||||
private readonly bitacoraMesaRepository: Repository<BitacoraMesa>,
|
private readonly bitacoraMesaRepository: Repository<BitacoraMesa>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async assignment(dto: CreateBitacoraMesaDto) {
|
async assignment(dto: CreateBitacoraMesaDto) {
|
||||||
const bitacora = this.bitacoraMesaRepository.create({
|
|
||||||
tiempo_entrada: new Date(),
|
|
||||||
tiempo_asignado: dto.tiempo_asignado,
|
|
||||||
mesa: { id_mesa: dto.id_mesa },
|
|
||||||
alumno_inscrito: { id_alumno_inscrito: dto.id_alumno_inscrito },
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.bitacoraMesaRepository.save(bitacora);
|
// VALIDAR: el alumno ya tiene una mesa activa
|
||||||
|
const alumnoConMesa = await this.bitacoraMesaRepository
|
||||||
|
.createQueryBuilder('bitacora')
|
||||||
|
.where('bitacora.id_alumno_inscrito = :id_alumno_inscrito', {
|
||||||
|
id_alumno_inscrito: dto.id_alumno_inscrito,
|
||||||
|
})
|
||||||
|
.andWhere(
|
||||||
|
`TIMESTAMPDIFF(
|
||||||
|
SECOND,
|
||||||
|
NOW(),
|
||||||
|
DATE_ADD(bitacora.tiempo_entrada, INTERVAL bitacora.tiempo_asignado MINUTE)
|
||||||
|
) > 0`,
|
||||||
|
)
|
||||||
|
.getOne();
|
||||||
|
|
||||||
|
if (alumnoConMesa) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'El alumno ya tiene una mesa asignada',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const bitacora = this.bitacoraMesaRepository.create({
|
||||||
|
tiempo_entrada: new Date(),
|
||||||
|
tiempo_asignado: dto.tiempo_asignado,
|
||||||
|
mesa: { id_mesa: dto.id_mesa },
|
||||||
|
alumno_inscrito: { id_alumno_inscrito: dto.id_alumno_inscrito },
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.bitacoraMesaRepository.save(bitacora);
|
||||||
|
}
|
||||||
|
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.bitacoraMesaRepository.find({
|
return this.bitacoraMesaRepository.find({
|
||||||
relations: ['mesa', 'alumno_inscrito'],
|
relations: ['mesa', 'alumno_inscrito'],
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export class BitacoraMesa {
|
|||||||
@Column({ name: 'tiempo_entrada', type: 'datetime' })
|
@Column({ name: 'tiempo_entrada', type: 'datetime' })
|
||||||
tiempo_entrada: Date;
|
tiempo_entrada: Date;
|
||||||
|
|
||||||
|
|
||||||
@ManyToOne(() => Mesa)
|
@ManyToOne(() => Mesa)
|
||||||
@JoinColumn({ name: 'id_mesa' })
|
@JoinColumn({ name: 'id_mesa' })
|
||||||
mesa: Mesa;
|
mesa: Mesa;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class MesaController {
|
|||||||
async findAllActivo() {
|
async findAllActivo() {
|
||||||
return this.mesaService.findAllActivo();
|
return this.mesaService.findAllActivo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
async updateActivo(
|
async updateActivo(
|
||||||
@Param('id') id: number,
|
@Param('id') id: number,
|
||||||
|
|||||||
@@ -9,12 +9,42 @@ export class MesaService {
|
|||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Mesa)
|
@InjectRepository(Mesa)
|
||||||
private readonly mesaRepository: Repository<Mesa>,
|
private readonly mesaRepository: Repository<Mesa>,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
|
async asignarMesa(idUsuario: number, idMesa: number) {
|
||||||
|
|
||||||
|
const yaTieneMesa = await this.mesaRepository.findOne({
|
||||||
|
where: { id_mesa: idMesa }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (yaTieneMesa) {
|
||||||
|
throw new BadRequestException('El usuario ya tiene una mesa asignada');
|
||||||
|
}
|
||||||
|
|
||||||
|
const mesa = await this.mesaRepository.findOne({
|
||||||
|
where: { id_mesa: idMesa }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!mesa) {
|
||||||
|
throw new NotFoundException('Mesa no existe');
|
||||||
|
}
|
||||||
|
|
||||||
|
mesa.activo = false;
|
||||||
|
await this.mesaRepository.save(mesa);
|
||||||
|
|
||||||
|
return await this.mesaRepository.save({
|
||||||
|
id_usuario: idUsuario,
|
||||||
|
id_mesa: idMesa,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async findAll(): Promise<Mesa[]> {
|
async findAll(): Promise<Mesa[]> {
|
||||||
return await this.mesaRepository.find();
|
return await this.mesaRepository.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async findAllActivo(): Promise<Mesa[]> {
|
async findAllActivo(): Promise<Mesa[]> {
|
||||||
return await this.mesaRepository.find({ where: { activo: true } });
|
return await this.mesaRepository.find({ where: { activo: true } });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user