regreso con numero inventario

This commit is contained in:
Lemuel Marquez
2021-05-31 15:45:04 -05:00
parent 028e9283e6
commit 829aa5e354
2 changed files with 61 additions and 0 deletions
@@ -0,0 +1,46 @@
const moment = require('moment');
const { validarId } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Prestamo = require(`${dbPath}/Prestamo`);
const Equipo = require(`${dbPath}/Equipo`);
const Operador = require(`${dbPath}/Operador`);
const regresarNumeroInventario = async (body) => {
const numeroInventario = validarAlfanumerico(
body.numeroInventario,
'El numero de inventario',
20
);
const idOperadorRegreso = validarId(body.idOperadorRegreso);
let idPrestamo;
const ahora = moment();
return Operador.findOne({ where: { idOperador: idOperadorRegreso } })
.then((res) => {
if (!res) throw new Error('No existe este operador.');
return Prestamo.findOne({
where: { activo: true },
include: [{ model: Equipo, where: { numeroInventario } }],
});
})
.then((res) => {
if (!res)
throw new Error('No existe un prestamo activo con este equipo.');
idPrestamo = res.idPrestamo;
return Equipo.update(
{ enUso: false, apartado: false },
{ where: { idEquipo: res.Equipo.idEquipo } }
);
})
.then((res) => {
Prestamo.update(
{ idOperadorRegreso, horaEntrega: ahora.format(), activo: false },
{ where: { idPrestamo } }
);
})
.then((res) => ({
message: 'Se ha regresado correctamente el equio de computo.',
}));
};
module.exports = regresarNumeroInventario;
+15
View File
@@ -10,6 +10,7 @@ const historialUsuario = require(`${controllerPath}/historialUsuario`);
const pedir = require(`${controllerPath}/pedir`);
const recoger = require(`${controllerPath}/recoger`);
const regresar = require(`${controllerPath}/regresar`);
const regresarNumeroInventario = require(`${controllerPath}/regresarNumeroInventario`);
const prestamo = require(`${controllerPath}/prestamo`);
const prestamoUsuario = require(`${controllerPath}/prestamoUsuario`);
const cancelar = require(`${controllerPath}/cancelar`);
@@ -57,6 +58,20 @@ app.put(
}
);
app.put(
`${route}/regresar_numero_inventario`,
// verificaToken,
(req, res) => {
return regresarNumeroInventario(req.body)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
}
);
app.put(
`${route}/cancelar`,
// verificaToken,