diff --git a/server/app.js b/server/app.js index 823e6de..01e910f 100644 --- a/server/app.js +++ b/server/app.js @@ -16,10 +16,6 @@ app.use( }) ); -io.on('connect', () => { - console.log('hola'); -}); - app.use(bodyParser.json()); app.get('/', (req, res) => res.send('API Pcpuma')); diff --git a/server/controller/Carrito/update.js b/server/controller/Carrito/update.js index 0ca3598..690cb06 100644 --- a/server/controller/Carrito/update.js +++ b/server/controller/Carrito/update.js @@ -11,7 +11,7 @@ const update = async (body) => { ); const idTipoCarrito = body.idTipoCarrito ? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true) - : null; + : ''; let update = {}; return TipoCarrito.findOne({ where: { idTipoCarrito } }) diff --git a/server/controller/Equipo/update.js b/server/controller/Equipo/update.js index f570870..e8373c4 100644 --- a/server/controller/Equipo/update.js +++ b/server/controller/Equipo/update.js @@ -13,13 +13,13 @@ const update = async (body) => { ); const idStatus = body.idStatus ? validar.validarNumeroEntero(body.idStatus, 'id status', true) - : null; + : ''; const idCarrito = body.idCarrito ? validar.validarNumeroEntero(body.idCarrito, 'id carrito', true) - : null; + : ''; const idPrograma = body.idPrograma ? validar.validarNumeroEntero(body.idPrograma, 'id programa', true) - : null; + : ''; let update = {}; return Status.findOne({ where: { idStatus } }) diff --git a/server/controller/Prestamo/activos.js b/server/controller/Prestamo/activos.js index 978c15e..54b3bca 100644 --- a/server/controller/Prestamo/activos.js +++ b/server/controller/Prestamo/activos.js @@ -20,10 +20,10 @@ const activos = async (body) => { ); const idPrestamo = body.idPrestamo ? validar.validarNumeroEntero(body.idPrestamo, 'id préstamo', true) - : null; + : ''; const idTipoCarrito = body.idTipoCarrito ? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true) - : null; + : ''; const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : ''; const numeroInventario = body.numeroInventario ? validar.validarAlfanumerico( @@ -33,21 +33,22 @@ const activos = async (body) => { 20 ) : ''; + let wherePrestamo = { + [Op.or]: [ + { activo: true }, + { + [Op.and]: [{ regresoInmediato: true }, { idOperadorRegreso: null }], + }, + ], + }; let whereCarrito = [{ idModulo }]; if (idTipoCarrito) whereCarrito.push({ idTipoCarrito }); + if (idPrestamo) wherePrestamo.idPrestamo = { [Op.like]: `%${idPrestamo}%` }; return Modulo.findOne({ where: { idModulo } }).then((res) => { if (!res) throw new Error('No existe este módulo.'); return Prestamo.findAndCountAll({ - where: { - [Op.or]: [ - { activo: true }, - { - [Op.and]: [{ regresoInmediato: true }, { idOperadorRegreso: null }], - }, - { idPrestamo: { [Op.like]: `%${idPrestamo}%` } }, - ], - }, + where: wherePrestamo, include: [ { model: Equipo, diff --git a/server/controller/Prestamo/historial.js b/server/controller/Prestamo/historial.js index 13a4a1a..8986572 100644 --- a/server/controller/Prestamo/historial.js +++ b/server/controller/Prestamo/historial.js @@ -16,7 +16,7 @@ const historial = async (body) => { const usuario = body.usuario ? validar.validarNumeroCuenta(body.usuario) : ''; const idPrestamo = body.idPrestamo ? validar.validarNumeroEntero(body.idPrestamo, 'id préstamo', true) - : null; + : ''; const numeroInventario = body.numeroInventario ? validar.validarAlfanumerico( body.numeroInventario, @@ -27,10 +27,10 @@ const historial = async (body) => { : ''; const idModulo = body.idModulo ? validar.validarNumeroEntero(body.idModulo, 'id módulo', true) - : null; + : ''; const idTipoCarrito = body.idTipoCarrito ? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true) - : null; + : ''; let whereCarrito = []; if (idTipoCarrito) whereCarrito.push({ idTipoCarrito }); diff --git a/server/controller/Prestamo/pedir.js b/server/controller/Prestamo/pedir.js index 4eecf53..f3c3872 100644 --- a/server/controller/Prestamo/pedir.js +++ b/server/controller/Prestamo/pedir.js @@ -23,10 +23,11 @@ const pedir = async (body) => { ); const idPrograma = body.idPrograma ? validarNumeroEntero(body.idPrograma, 'id programa', true) - : null; + : ''; const idModulo = idPrograma ? 1 : validarNumeroEntero(body.idModulo, 'id modulo', true); + let whereEquipo = { idStatus: 4 }; let idEquipo; // if (ahora > horaMax) @@ -44,6 +45,7 @@ const pedir = async (body) => { }) .then((res) => { if (!res && idPrograma) throw new Error('No existe este programa.'); + if (idPrograma) whereEquipo.idPrograma = idPrograma; return Usuario.findOne({ where: { idUsuario } }); }) .then((res) => { @@ -79,10 +81,7 @@ const pedir = async (body) => { ); } return Equipo.findOne({ - where: { - idStatus: 4, - idPrograma, - }, + where: whereEquipo, include: [ { model: Carrito, diff --git a/server/controller/Prestamo/prestamo.js b/server/controller/Prestamo/prestamo.js index 615000e..5d9feb3 100644 --- a/server/controller/Prestamo/prestamo.js +++ b/server/controller/Prestamo/prestamo.js @@ -7,6 +7,7 @@ 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`); @@ -26,6 +27,7 @@ const prestamo = async (body) => { attributes: ['idCarrito', 'carrito'], }, { model: Programa }, + { model: Status }, ], attributes: ['idEquipo', 'numeroSerie', 'numeroInventario', 'equipo'], }, diff --git a/server/controller/Prestamo/reporte.js b/server/controller/Prestamo/reporte.js index 63b1c30..91517ca 100644 --- a/server/controller/Prestamo/reporte.js +++ b/server/controller/Prestamo/reporte.js @@ -21,13 +21,13 @@ const reporte = async (body) => { const fin = validar.validarFecha(body.fin, 'fecha fin', false); const idCarrera = body.idCarrera ? validar.validarNumeroEntero(body.idCarrera, 'id carrera', true) - : null; + : ''; const idTipoUsuario = body.idTipoUsuario ? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true) - : null; + : ''; const idTipoCarrito = body.idTipoCarrito ? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true) - : null; + : ''; const path = `server/uploads/reporte.csv`; const data = []; @@ -106,7 +106,7 @@ const reporte = async (body) => { equipo: res[i].Equipo.equipo, programa: res[i].Equipo.Programa ? res[i].Equipo.Programa.programa - : null, + : '', carrito: res[i].Equipo.Carrito.carrito, modulo: res[i].Equipo.Carrito.Modulo.modulo, tipoCarrito: res[i].Equipo.Carrito.TipoCarrito.tipoCarrito, @@ -116,10 +116,10 @@ const reporte = async (body) => { carrera: res[i].Usuario.Carrera.carrera, operadorEntrega: res[i].OperadorEntrega ? res[i].OperadorEntrega.operador - : null, + : '', operadorRegreso: res[i].OperadorRegreso ? res[i].OperadorRegreso.operador - : null, + : '', }); } await helper.eliminarArchivo(path).catch((err) => {}); diff --git a/server/controller/Status/get.js b/server/controller/Status/get.js index 19f85b1..2bed16c 100644 --- a/server/controller/Status/get.js +++ b/server/controller/Status/get.js @@ -1,6 +1,5 @@ -const { Op } = require('sequelize'); const Status = require('../../db/tablas/Status'); -const get = async () => Status.findAll({ where: { idStatus: { [Op.gt]: 3 } } }); +const get = async () => Status.findAll(); module.exports = get; diff --git a/server/controller/Usuario/usuarios.js b/server/controller/Usuario/usuarios.js index 183047c..9f9e2d9 100644 --- a/server/controller/Usuario/usuarios.js +++ b/server/controller/Usuario/usuarios.js @@ -13,7 +13,7 @@ const usuarios = async (body) => { : ''; const idTipoUsuario = body.idTipoUsuario ? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true) - : null; + : ''; return Usuario.findAndCountAll({ where: { diff --git a/server/routes/Prestamo.js b/server/routes/Prestamo.js index 8cf5eb1..139ba48 100644 --- a/server/routes/Prestamo.js +++ b/server/routes/Prestamo.js @@ -87,6 +87,7 @@ app.put( ); app.put(`${route}/cancelar_usuario`, verificaToken, (req, res) => { + req.body.idUsuario = req.decoded.data.idUsuario; return cancelarUsuario(req.body) .then((data) => { res.status(200).json(data);