traer a todos los responsables
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user