From 19a3255e6dc3485d6afb265dacf7dc044e1e1000 Mon Sep 17 00:00:00 2001 From: lemuel Date: Fri, 19 Aug 2022 19:17:11 -0500 Subject: [PATCH] hora tope arreglado --- src/prestamo/prestamo.service.ts | 47 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/prestamo/prestamo.service.ts b/src/prestamo/prestamo.service.ts index 87560a8..9f7771c 100644 --- a/src/prestamo/prestamo.service.ts +++ b/src/prestamo/prestamo.service.ts @@ -110,6 +110,7 @@ export class PrestamoService { id_tipo_entrada?: number, ) { const ahora = moment(); + const ahoraStr = ahora.format('YYYY-MM-DD'); const sistema = await this.operadorService.findById(1); const modulo = await this.moduloService.findById(id_modulo); const tipoCarrito = @@ -121,17 +122,11 @@ export class PrestamoService { modulo.institucion, ahora.weekday(), ); - const horaMax = institucionDia - ? moment(`${ahora.format('YYYY-MM-DD')} ${institucionDia.hora_fin}`) - : null; const horaMin = institucionDia - ? moment(`${ahora.format('YYYY-MM-DD')} ${institucionDia.hora_inicio}`) + ? moment(`${ahoraStr} ${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}`) + ? moment(`${ahoraStr} ${institucionDia.hora_extra}`) : null; const programa = id_programa ? await this.institucionProgramaService.findProgramaById(id_programa) @@ -159,14 +154,10 @@ export class PrestamoService { ); for (let i = 0; i < institucionDia.horasExcepcion.length; i++) { const horaFin = moment( - `${ahora.format('YYYY-MM-DD')} ${ - institucionDia.horasExcepcion[i].hora_fin - }`, + `${ahoraStr} ${institucionDia.horasExcepcion[i].hora_fin}`, ); const horaInicio = moment( - `${ahora.format('YYYY-MM-DD')} ${ - institucionDia.horasExcepcion[i].hora_inicio - }`, + `${ahoraStr} ${institucionDia.horasExcepcion[i].hora_inicio}`, ); if (ahora > horaInicio && ahora < horaFin) @@ -199,11 +190,10 @@ export class PrestamoService { this.repository.save( this.repository.create({ equipo, - fecha_inicio: ahora.format(), - hora_max_recoger: - ahora > horaMax && ahora < horaExtra - ? horaTope.format() - : ahora.add(modulo.institucion.tiempo_recoger, 'm').format(), + fecha_inicio: ahora.toDate(), + hora_max_recoger: ahora + .add(modulo.institucion.tiempo_recoger, 'm') + .toDate(), operadorEntrega: sistema, operadorRegreso: sistema, usuario, @@ -248,8 +238,20 @@ export class PrestamoService { async entregar(id_prestamo: number, id_operador: number) { const ahora = moment(); + const ahoraStr = ahora.format('YYYY-MM-DD'); const operadorEntrega = await this.operadorService.findById(id_operador); const prestamo = await this.findById(id_prestamo); + const institucionDia = + await this.institucionDiaService.findByInstitucionDia( + operadorEntrega.institucion, + ahora.weekday(), + ); + const horaTope = institucionDia + ? moment(`${ahoraStr} ${institucionDia.hora_tope}`) + : null; + const horaMax = institucionDia + ? moment(`${ahoraStr} ${institucionDia.hora_fin}`) + : null; this.validacionBasicaPrestamo(prestamo, operadorEntrega); if (prestamo.equipo.status.id_status === 3) @@ -257,9 +259,10 @@ export class PrestamoService { 'Ya se entregó el equipo de cómputo al usuario.', ); prestamo.hora_inicio = ahora.toDate(); - prestamo.hora_fin = ahora - .add(operadorEntrega.institucion.tiempo_prestamo, 'm') - .toDate(); + prestamo.hora_fin = + ahora > horaMax + ? horaTope.toDate() + : ahora.add(operadorEntrega.institucion.tiempo_prestamo, 'm').toDate(); prestamo.operadorEntrega = operadorEntrega; prestamo.equipo.prestado = true; return this.repository