listo hora top y hora extra

This commit is contained in:
lemuel 2022-08-06 19:52:40 -05:00
parent 101cfb6275
commit b89bed1d74

View File

@ -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.`,
);
}