get endpoints prestamos
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
|
||||
const activos = async (body) => {
|
||||
return Prestamo.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
where: { activo: true },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
],
|
||||
},
|
||||
{ model: Usuario, include: [{ model: TipoUsuario }, { model: Carrera }] },
|
||||
],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
delete res[i].dataValues.idUsuario;
|
||||
delete res[i].dataValues.idOperadorEntrega;
|
||||
delete res[i].dataValues.idEquipo;
|
||||
delete res[i].dataValues.idStatus;
|
||||
delete res[i].dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res[i].dataValues.Carrito.dataValues.idModulo;
|
||||
delete res[i].dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res[i].dataValues.Usuario.dataValues.idCarrera;
|
||||
if (res[i].idPrograma) delete res[i].dataValues.idPrograma;
|
||||
}
|
||||
return { activos: res };
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = activos;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
|
||||
const historial = async (body) => {
|
||||
return Prestamo.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
],
|
||||
},
|
||||
{ model: Usuario, include: [{ model: TipoUsuario }, { model: Carrera }] },
|
||||
],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
delete res[i].dataValues.idUsuario;
|
||||
delete res[i].dataValues.idOperadorEntrega;
|
||||
delete res[i].dataValues.idEquipo;
|
||||
delete res[i].dataValues.idStatus;
|
||||
delete res[i].dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res[i].dataValues.Carrito.dataValues.idModulo;
|
||||
delete res[i].dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res[i].dataValues.Usuario.dataValues.idCarrera;
|
||||
if (res[i].idPrograma) delete res[i].dataValues.idPrograma;
|
||||
}
|
||||
return { historial: res };
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historial;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
|
||||
const historialEquipo = async (body) => {
|
||||
let numeroSerie = validar.validarAlfanumerico(
|
||||
body.numeroSerie,
|
||||
'El numero de serie',
|
||||
20
|
||||
);
|
||||
|
||||
return Prestamo.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
where: { numeroSerie },
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
],
|
||||
},
|
||||
{ model: Usuario, include: [{ model: TipoUsuario }, { model: Carrera }] },
|
||||
],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
delete res[i].dataValues.idUsuario;
|
||||
delete res[i].dataValues.idOperadorEntrega;
|
||||
delete res[i].dataValues.idEquipo;
|
||||
delete res[i].dataValues.idStatus;
|
||||
delete res[i].dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res[i].dataValues.Carrito.dataValues.idModulo;
|
||||
delete res[i].dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res[i].dataValues.Usuario.dataValues.idCarrera;
|
||||
if (res[i].idPrograma) delete res[i].dataValues.idPrograma;
|
||||
}
|
||||
return { historialEquipo: res };
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historialEquipo;
|
||||
@@ -0,0 +1,48 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
|
||||
const historialUsuario = async (body) => {
|
||||
let usuario = validar.validarNumeroCuenta(body.noCuenta);
|
||||
|
||||
return Prestamo.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
where: { usuario },
|
||||
include: [{ model: TipoUsuario }, { model: Carrera }],
|
||||
},
|
||||
],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
delete res[i].dataValues.idUsuario;
|
||||
delete res[i].dataValues.idOperadorEntrega;
|
||||
delete res[i].dataValues.idEquipo;
|
||||
delete res[i].dataValues.idStatus;
|
||||
delete res[i].dataValues.Carrito.dataValues.idTipoCarrito;
|
||||
delete res[i].dataValues.Carrito.dataValues.idModulo;
|
||||
delete res[i].dataValues.Usuario.dataValues.idTipoUsuario;
|
||||
delete res[i].dataValues.Usuario.dataValues.idCarrera;
|
||||
if (res[i].idPrograma) delete res[i].dataValues.idPrograma;
|
||||
}
|
||||
return { historialUsuario: res };
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historialUsuario;
|
||||
|
||||
@@ -36,4 +36,5 @@ app.post(
|
||||
.json({ message: 'No se envio un archivo csv para la carga masiva.' });
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
|
||||
+63
-11
@@ -2,17 +2,69 @@ const express = require('express');
|
||||
const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/prestamo';
|
||||
// const login = require('../controller/Prestamo/');
|
||||
const controllerPath = '../controller/Prestamo';
|
||||
const activos = require(`${controllerPath}/activos`);
|
||||
const historial = require(`${controllerPath}/historial`);
|
||||
const historialEquipo = require(`${controllerPath}/activos`);
|
||||
const historialUsuario = require(`${controllerPath}/historialUsuario`);
|
||||
|
||||
// app.post(`${route}/`, (req, res) => {
|
||||
// return login(req.body)
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.log(err);
|
||||
// res.status(400).json({ message: err.message });
|
||||
// });
|
||||
// });
|
||||
app.get(
|
||||
`${route}/activos`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return activos(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.get(
|
||||
`${route}/historial`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return historial(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.get(
|
||||
`${route}/historial_equipo`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return historialEquipo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.get(
|
||||
`${route}/historial_usuario`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return historialUsuario(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
module.exports = app;
|
||||
|
||||
@@ -3,6 +3,7 @@ const app = express();
|
||||
|
||||
app.use(require('./Operador'));
|
||||
app.use(require('./Usuario'));
|
||||
app.use(require('./Prestamo'));
|
||||
app.use(require('./Equipo'));
|
||||
app.use(require('./TipoCarrito'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user