operadores endpoint

This commit is contained in:
Lemuel Marquez
2021-05-04 00:32:04 -05:00
parent d17a12b379
commit cfe9a52bae
10 changed files with 48 additions and 15 deletions
+2 -2
View File
@@ -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;
+3 -3
View File
@@ -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;
+22
View File
@@ -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;
+1 -1
View File
@@ -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 };
});
};
@@ -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 };
});
};
@@ -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 };
});
};
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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;
+3 -3
View File
@@ -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;
+11
View File
@@ -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;