From b89bed1d749dd1e49e3772508e0a9c43a286d1cd Mon Sep 17 00:00:00 2001 From: lemuel Date: Sat, 6 Aug 2022 19:52:40 -0500 Subject: [PATCH] listo hora top y hora extra --- src/prestamo/prestamo.service.ts | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/prestamo/prestamo.service.ts b/src/prestamo/prestamo.service.ts index 3df0a5c..b10e851 100644 --- a/src/prestamo/prestamo.service.ts +++ b/src/prestamo/prestamo.service.ts @@ -1,6 +1,8 @@ import * as moment from 'moment'; import { + BadRequestException, ConflictException, + ForbiddenException, forwardRef, Inject, Injectable, @@ -121,6 +123,12 @@ export class PrestamoService { const horaMin = institucionDia ? moment(`${ahora.format('YYYY-MM-DD')} ${institucionDia.hora_inicio}`) : null; + const horaExtra = institucionDia + ? moment(`${ahora.format('YYYY-MM-DD')} ${institucionDia.hora_extra}`) + : null; + const horaTope = institucionDia + ? moment(`${ahora.format('YYYY-MM-DD')} ${institucionDia.hora_tope}`) + : null; const programa = id_programa ? await this.institucionProgramaService.findProgramaById(id_programa) : null; @@ -130,9 +138,9 @@ export class PrestamoService { ) : null; + if (ahora.weekday() === 0) + throw new ConflictException('No hay servicio los días domingo.'); this.validarInstitucionUsuario(usuario.instituciones, modulo); - if (ahora.weekday() === 0 || ahora.weekday() === 6) - throw new ConflictException('No hay servicio los días sábado y domingo.'); if (!institucionDia.activo) throw new ConflictException( 'El día de hoy no hay servicio de préstamo de equipos.', @@ -141,9 +149,9 @@ export class PrestamoService { throw new ConflictException( `El servicio inicia a las ${institucionDia.hora_inicio} el día de hoy.`, ); - if (ahora > horaMax) + if (ahora >= horaExtra) throw new ConflictException( - `El servicio terminó a las ${institucionDia.hora_fin} el día de hoy.`, + `El servicio terminó a las ${institucionDia.hora_extra} el día de hoy.`, ); for (let i = 0; i < institucionDia.horasExcepcion.length; i++) { const horaFin = moment( @@ -188,9 +196,10 @@ export class PrestamoService { this.repository.create({ equipo, fecha_inicio: ahora.toDate(), - hora_max_recoger: ahora - .add(modulo.institucion.tiempo_recoger, 'm') - .toDate(), + hora_max_recoger: + ahora > horaMax && ahora < horaExtra + ? horaTope + : ahora.add(modulo.institucion.tiempo_recoger, 'm').toDate(), operadorEntrega: sistema, operadorRegreso: sistema, usuario, @@ -667,17 +676,17 @@ export class PrestamoService { if (institucion.id_institucion === modulo.institucion.id_institucion) { if (!instituciones[i].activo) - throw new ConflictException( + throw new ForbiddenException( `${this.mensajeNoPoderPedir()} tu cuenta esta desactivada en esta institución.`, ); if (instituciones[i].multa) - throw new ConflictException( + throw new ForbiddenException( `${this.mensajeNoPoderPedir()} tienes una multa activa.`, ); - return; + return institucion; } } - throw new ConflictException( + throw new BadRequestException( `${this.mensajeNoPoderPedir()} no perteneces a esta institución.`, ); }