get prestamo por numero inventario
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
const { validarAlfanumerico } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const prestamoNumeroInventario = async (body) => {
|
||||
const numeroInventario = validarAlfanumerico(
|
||||
body.numeroInventario,
|
||||
'numero de inventario',
|
||||
true,
|
||||
20
|
||||
);
|
||||
|
||||
return Prestamo.findOne({
|
||||
where: { activo: true },
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
where: { numeroInventario },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
attributes: ['idCarrito', 'carrito'],
|
||||
},
|
||||
{ model: Programa },
|
||||
{ model: Status },
|
||||
],
|
||||
attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
attributes: ['idUsuario', 'usuario', 'nombre'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorEntrega',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorRegreso',
|
||||
attributes: ['idOperador', 'operador'],
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
'idPrestamo',
|
||||
'activo',
|
||||
'horaMaxRecoger',
|
||||
'horaInicio',
|
||||
'horaFin',
|
||||
'horaEntrega',
|
||||
'canceladoUsuario',
|
||||
'canceladoOperador',
|
||||
'regresoInmediato',
|
||||
'createdAt',
|
||||
],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe este préstamo.');
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = prestamoNumeroInventario;
|
||||
@@ -9,7 +9,7 @@ const Status = require(`${dbPath}/Status`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const prestamo = async (body) => {
|
||||
const prestamoUsuario = async (body) => {
|
||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario', true);
|
||||
|
||||
return Usuario.findOne({ where: { idUsuario } }).then((res) => {
|
||||
@@ -47,4 +47,4 @@ const prestamo = async (body) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = prestamo;
|
||||
module.exports = prestamoUsuario;
|
||||
|
||||
@@ -16,6 +16,7 @@ const regresarNumeroInventario = require(`${controllerPath}/regresarNumeroInvent
|
||||
const regresoInmediato = require(`${controllerPath}/regresoInmediato`);
|
||||
const regresoInmediatoNumeroInventario = require(`${controllerPath}/regresoInmediatoNumeroInventario`);
|
||||
const prestamo = require(`${controllerPath}/prestamo`);
|
||||
const prestamoNumeroInventario = require(`${controllerPath}/prestamoNumeroInventario`);
|
||||
const prestamoUsuario = require(`${controllerPath}/prestamoUsuario`);
|
||||
const reporte = require(`${controllerPath}/reporte`);
|
||||
const status = require(`${controllerPath}/status`);
|
||||
@@ -158,6 +159,16 @@ app.get(`${route}`, verificaToken, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/prestamo_numero_inventario`, verificaToken, (req, res) => {
|
||||
return prestamoNumeroInventario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/prestamo_usuario`, verificaToken, (req, res) => {
|
||||
return prestamoUsuario(req.query)
|
||||
.then((data) => {
|
||||
|
||||
Reference in New Issue
Block a user