diff --git a/server/controller/Equipo/equipo.js b/server/controller/Equipo/equipo.js index 46a14be..edd8654 100644 --- a/server/controller/Equipo/equipo.js +++ b/server/controller/Equipo/equipo.js @@ -7,7 +7,7 @@ const Programa = require(`${dbPath}/Programa`); const Status = require(`${dbPath}/Status`); const TipoCarrito = require(`${dbPath}/TipoCarrito`); -const get = async (body) => { +const equipo = async (body) => { let numeroSerie = validar.validarAlfanumerico( body.numeroSerie, 'El numero de serie', @@ -33,4 +33,4 @@ const get = async (body) => { }); }; -module.exports = get; +module.exports = equipo; diff --git a/server/controller/Equipo/equipos.js b/server/controller/Equipo/equipos.js index 3e9c494..ed0a305 100644 --- a/server/controller/Equipo/equipos.js +++ b/server/controller/Equipo/equipos.js @@ -7,7 +7,7 @@ const Programa = require(`${dbPath}/Programa`); const Status = require(`${dbPath}/Status`); const TipoCarrito = require(`${dbPath}/TipoCarrito`); -const get = async (body) => { +const equipos = async (body) => { const pagina = validar.validarNumero(body.pagina); return Equipo.findAndCountAll({ @@ -27,8 +27,8 @@ const get = async (body) => { delete res.rows[i].dataValues.Carrito.dataValues.idModulo; if (!res.rows[i].Programa) delete res.rows[i].dataValues.Programa; } - return res; + return { count: res.count, equipos: res.rows }; }); }; -module.exports = get; +module.exports = equipos; diff --git a/server/controller/Operador/operadores.js b/server/controller/Operador/operadores.js index e69de29..e6165d1 100644 --- a/server/controller/Operador/operadores.js +++ b/server/controller/Operador/operadores.js @@ -0,0 +1,22 @@ +const validar = require('../../helper/validar'); +const Operador = require('../../db/tablas/Operador'); +const TipoUsuario = require('../../db/tablas/TipoUsuario'); + +const operadores = async (body) => { + const pagina = validar.validarNumero(body.pagina); + + return Operador.findAndCountAll({ + where: { idTipoUsuario: 2 }, + include: [{ model: TipoUsuario }], + limit: 25, + offset: 25 * (pagina - 1), + }).then((res) => { + for (let i = 0; i < res.rows.length; i++) { + delete res.rows[i].dataValues.password; + delete res.rows[i].dataValues.idTipoUsuario; + } + return { count: res.count, operadores: res.rows }; + }); +}; + +module.exports = operadores; diff --git a/server/controller/Prestamo/historial.js b/server/controller/Prestamo/historial.js index 2a0c5a4..c8c8c04 100644 --- a/server/controller/Prestamo/historial.js +++ b/server/controller/Prestamo/historial.js @@ -53,7 +53,7 @@ const historial = async (body) => { delete res.rows[i].dataValues.OperadorRegreso; else delete res.rows[i].dataValues.OperadorRegreso.dataValues.password; } - return { historial: res }; + return { count: res.count, historial: res.rows }; }); }; diff --git a/server/controller/Prestamo/historialEquipo.js b/server/controller/Prestamo/historialEquipo.js index 28ca473..d599784 100644 --- a/server/controller/Prestamo/historialEquipo.js +++ b/server/controller/Prestamo/historialEquipo.js @@ -37,7 +37,7 @@ const historialEquipo = async (body) => { delete res.rows[i].dataValues.OperadorRegreso; else delete res.rows[i].dataValues.OperadorRegreso.dataValues.password; } - return { historialEquipo: res }; + return { count: res.count, historialEquipo: res.rows }; }); }; diff --git a/server/controller/Prestamo/historialUsuario.js b/server/controller/Prestamo/historialUsuario.js index 874e0ef..54e9f0d 100644 --- a/server/controller/Prestamo/historialUsuario.js +++ b/server/controller/Prestamo/historialUsuario.js @@ -55,7 +55,7 @@ const historialUsuario = async (body) => { delete res.rows[i].dataValues.OperadorRegreso; else delete res.rows[i].dataValues.OperadorRegreso.dataValues.password; } - return { historialUsuario: res }; + return { count: res.count, historialUsuario: res.rows }; }); }; diff --git a/server/controller/Prestamo/regresar.js b/server/controller/Prestamo/regresar.js index 97c07b2..37a59b5 100644 --- a/server/controller/Prestamo/regresar.js +++ b/server/controller/Prestamo/regresar.js @@ -5,7 +5,7 @@ const Prestamo = require(`${dbPath}/Prestamo`); const Equipo = require(`${dbPath}/Equipo`); const Operador = require(`${dbPath}/Operador`); -const recoger = async (body) => { +const regresar = async (body) => { const idPrestamo = validar.validarId(body.idPrestamo); const idOperadorRegreso = validar.validarId(body.idOperadorRegreso); const ahora = moment(); @@ -39,4 +39,4 @@ const recoger = async (body) => { })); }; -module.exports = recoger; +module.exports = regresar; diff --git a/server/controller/Usuario/usuario.js b/server/controller/Usuario/usuario.js index 74c2657..e5a49d5 100644 --- a/server/controller/Usuario/usuario.js +++ b/server/controller/Usuario/usuario.js @@ -4,7 +4,7 @@ const Usuario = require(`${dbPath}/Usuario`); const Carrera = require(`${dbPath}/Carrera`); const TipoUsuario = require(`${dbPath}/TipoUsuario`); -const get = async (body) => { +const usuario = async (body) => { const usuario = validar.validarNumeroCuenta(body.usuario); return Usuario.findOne({ @@ -20,4 +20,4 @@ const get = async (body) => { }); }; -module.exports = get; +module.exports = usuario; diff --git a/server/controller/Usuario/usuarios.js b/server/controller/Usuario/usuarios.js index 71dee6f..1f59ae2 100644 --- a/server/controller/Usuario/usuarios.js +++ b/server/controller/Usuario/usuarios.js @@ -4,7 +4,7 @@ const Usuario = require(`${dbPath}/Usuario`); const Carrera = require(`${dbPath}/Carrera`); const TipoUsuario = require(`${dbPath}/TipoUsuario`); -const get = async (body) => { +const usuarios = async (body) => { const pagina = validar.validarNumero(body.pagina); return Usuario.findAndCountAll({ @@ -18,8 +18,8 @@ const get = async (body) => { delete res.rows[i].dataValues.idCarrera; if (!res.rows[i].Carrera) delete res.rows[i].dataValues.Carrera; } - return res; + return { count: res.count, usuarios: res.rows }; }); }; -module.exports = get; +module.exports = usuarios; diff --git a/server/routes/Operador.js b/server/routes/Operador.js index 1104c95..ff5bc00 100644 --- a/server/routes/Operador.js +++ b/server/routes/Operador.js @@ -5,6 +5,7 @@ const route = '/operador'; const controllerPath = '../controller/Operador'; const login = require(`${controllerPath}/login`); const crear = require(`${controllerPath}/crear`); +const operadores = require(`${controllerPath}/operadores`); app.post(`${route}/login`, (req, res) => { return login(req.body) @@ -26,4 +27,14 @@ app.post(`${route}/crear`, (req, res) => { }); }); +app.get(`${route}/operadores`, (req, res) => { + return operadores(req.query) + .then((data) => { + res.status(201).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + module.exports = app;