traer a todos los responsables

This commit is contained in:
2020-11-19 12:23:39 -06:00
parent 9b748bc130
commit d5271cd086
5 changed files with 63 additions and 4 deletions
-2
View File
@@ -40,9 +40,7 @@ const admin = (body) => {
Usuario: {
idUsuario: res.Usuario.idUsuario,
usuario: res.Usuario.usuario,
password: res.Usuario.password,
nombre: res.Usuario.nombre,
activo: res.Usuario.activo,
TipoUsuario: {
idTipoUsuario: res.Usuario.TipoUsuario.idTipoUsuario,
tipoUsuario: res.Usuario.TipoUsuario.tipoUsuario,
+1 -1
View File
@@ -22,7 +22,7 @@ const serviciosAdmin = async (body) => {
return Usuario.findOne({ where: { idUsuario } })
.then((res) => {
if (!res) throw new Error('No existe este usuario.');
if (res.idTipoUsuario != 1)
if (res.idTipoUsuario !== 1)
throw new Error('No es un usuario tipo admin.');
return Servicio.findAll({
where,
@@ -23,7 +23,7 @@ const serviciosResponsable = async (body) => {
return Usuario.findOne({ where: { idUsuario } })
.then((res) => {
if (!res) throw new Error('No existe este usuario.');
if (res.idTipoUsuario != 2)
if (res.idTipoUsuario !== 2)
throw new Error('No es un usuario tipo responsable.');
return Servicio.findAll({
where,
+50
View File
@@ -0,0 +1,50 @@
const { Op } = require('sequelize');
const validar = require('../../helper/validar');
const Usuario = require('../../db/tablas/Usuario');
const TipoUsuario = require('../../db/tablas/TipoUsuario');
const responsable = async (body) => {
let pagina = validar.validarId(body.pagina);
let idUsuario = validar.validarId(body.idUsuario);
let nombre = body.nombre
? validar.validarTexto(body.nombre, 'El nombre')
: '';
let correo = body.correo ? validar.validar(body.correo, 'El correo') : '';
return Usuario.findOne({ where: { idUsuario } })
.then((res) => {
if (!res) throw new Error('No existe este usuario.');
if (res.idTipoUsuario !== 1)
throw new Error('No es un usuario tipo admin.');
return Usuario.findAll({
where: {
usuario: { [Op.like]: `%${correo}%` },
nombre: { [Op.like]: `%${nombre}%` },
idTipoUsuario: 2,
},
include: [{ model: TipoUsuario }],
});
})
.then((res) => {
let data = [];
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++)
data.push({
idUsuario: res[i].idUsuario,
usuario: res[i].usuario,
nombre: res[i].nombre,
activo: res[i].activo,
TipoUsuario: {
idTipoUsuario: res[i].TipoUsuario.idTipoUsuario,
tipoUsuario: res[i].TipoUsuario.tipoUsuario,
},
});
return {
registros: res.length,
faltantes: res.length - data.length - (pagina - 1) * 25,
servicios: data,
};
});
};
module.exports = responsable;
+11
View File
@@ -3,6 +3,7 @@ const app = express();
const route = '/usuario';
const escolares = require('../controller/Usuario/escolares');
const login = require('../controller/Usuario/login');
const responsable = require('../controller/Usuario/responsable');
app.post(`${route}/login`, (req, res) => {
return login(req.body)
@@ -24,4 +25,14 @@ app.get(`${route}/escolares`, (req, res) => {
});
});
app.get(`${route}/responsable`, (req, res) => {
return responsable(req.query)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
module.exports = app;