Merge branch 'tomy' of https://repositorio.acatlan.unam.mx/CIDWA/pcpuma_acatlan_api into dev
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
const Infraccion = require('../../db/tablas/Infraccion');
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const get = async () => Infraccion.findAll();
|
||||
const get = async () =>
|
||||
Infraccion.findAll({ where: { idInfraccion: { [Op.ne]: 1 } } });
|
||||
|
||||
module.exports = get;
|
||||
|
||||
@@ -18,10 +18,9 @@ const multar = async (body) => {
|
||||
);
|
||||
let prestamo = {};
|
||||
let fechaFin = moment();
|
||||
|
||||
return Operador.findOne({ where: { idOperador: idOperadorMulta } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta este operador.');
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
return Infraccion.findOne({ where: { idInfraccion } });
|
||||
})
|
||||
.then((res) => {
|
||||
@@ -55,7 +54,9 @@ const multar = async (body) => {
|
||||
idPrestamo,
|
||||
})
|
||||
)
|
||||
.then((res) => ({ message: `Se levantó correctamente el reporte de multa.` }));
|
||||
.then((res) => ({
|
||||
message: `Se levantó correctamente el reporte de multa.`,
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = multar;
|
||||
|
||||
@@ -12,14 +12,22 @@ const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const pedir = async (body) => {
|
||||
const ahora = moment();
|
||||
const horaMax = moment().format('20:00:00');
|
||||
const horaMin = moment().format('09:00:00');
|
||||
const idUsuario = validarId(body.idUsuario);
|
||||
const idTipoCarrito = validarId(body.idTipoCarrito);
|
||||
const idPrograma = body.idPrograma ? validarId(body.idPrograma) : null;
|
||||
const idModulo = idPrograma ? 1 : validarId(body.idModulo);
|
||||
let idEquipo;
|
||||
|
||||
// Checar que sea en el horario establecido
|
||||
return TipoCarrito.findOne({ where: { idTipoCarrito } })
|
||||
.then((res) => {
|
||||
if (ahora.format('HH:mm:ss') > horaMax)
|
||||
throw new Error('Es demasido tarde para otorgar prestamos');
|
||||
if (ahora.format('HH:mm:ss') < horaMin)
|
||||
throw new Error('Es demasido temprano para otorgar prestamos');
|
||||
return Prestamo.findOne({ where: { idUsuario } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este tipo de equipo.');
|
||||
return Modulo.findOne({ where: { idModulo } });
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const moment = require('moment');
|
||||
const multar = require('../Multa/multar');
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const prestamo = require('./prestamoUsuario');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
@@ -10,7 +12,6 @@ const regresar = async (body) => {
|
||||
const idOperadorRegreso = validarId(body.idOperadorRegreso);
|
||||
const ahora = moment();
|
||||
|
||||
// Multar por hora de entrega
|
||||
return Operador.findOne({ where: { idOperador: idOperadorRegreso } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
@@ -19,18 +20,28 @@ const regresar = async (body) => {
|
||||
include: [{ model: Equipo }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
if (!res.activo) throw new Error('Este prestamo ya no esta activo.');
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este préstamo.');
|
||||
if (!res.activo) throw new Error('Este préstamo ya no esta activo.');
|
||||
if (!res.Equipo.enUso)
|
||||
throw new Error('Aun no se ha entregado el equipo al usuario.');
|
||||
|
||||
if (res.horaFin < ahora) {
|
||||
await multar({
|
||||
idOperadorMulta: idOperadorRegreso,
|
||||
idPrestamo: res.idPrestamo,
|
||||
idInfraccion: 1,
|
||||
descripcion: 'Demora',
|
||||
});
|
||||
}
|
||||
|
||||
return Equipo.update(
|
||||
{ enUso: false, apartado: false },
|
||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
Prestamo.update(
|
||||
.then(async (res) => {
|
||||
await Prestamo.update(
|
||||
{ idOperadorRegreso, horaEntrega: ahora.format(), activo: false },
|
||||
{ where: { idPrestamo } }
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const moment = require('moment');
|
||||
const multar = require('../Multa/multar');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
@@ -23,12 +24,21 @@ const regresarNumeroInventario = async (body) => {
|
||||
include: [{ model: Equipo, where: { numeroInventario } }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
.then(async (res) => {
|
||||
if (!res)
|
||||
throw new Error('No existe un prestamo activo con este equipo.');
|
||||
if (!res.Equipo.enUso)
|
||||
throw new Error('Aun no se ha entregado el equipo al usuario.');
|
||||
idPrestamo = res.idPrestamo;
|
||||
|
||||
if (res.horaFin < ahora) {
|
||||
await multar({
|
||||
idOperadorMulta: idOperadorRegreso,
|
||||
idPrestamo: res.idPrestamo,
|
||||
idInfraccion: 1,
|
||||
descripcion: 'Demora',
|
||||
});
|
||||
}
|
||||
return Equipo.update(
|
||||
{ enUso: false, apartado: false },
|
||||
{ where: { idEquipo: res.Equipo.idEquipo } }
|
||||
|
||||
Reference in New Issue
Block a user