Files
servicio_social_api/server/controller/Programa/programasAdmin.js
T

23 lines
632 B
JavaScript
Raw Normal View History

2020-11-16 18:53:11 -06:00
const validar = require('../../helper/validar');
const Programa = require('../../db/tablas/Programa');
const Usuario = require('../../db/tablas/Usuario');
2021-01-11 03:21:34 -06:00
const programasAdmin = async (body) => {
2021-01-14 03:13:37 -06:00
const idUsuario = validar.validarId(body.idUsuario);
2020-11-16 18:53:11 -06:00
return Usuario.findOne({
2020-11-17 13:49:31 -06:00
where: { idUsuario },
2020-11-16 18:53:11 -06:00
})
.then((res) => {
2020-11-17 13:49:31 -06:00
if (!res) throw new Error('No existe este usuario.');
if (res.idTipoUsuario != 2)
throw new Error('No es un usuario de tipo responsable');
2020-11-16 18:53:11 -06:00
return Programa.findAll({
2021-01-11 03:21:34 -06:00
where: { idUsuario },
2020-11-16 18:53:11 -06:00
});
})
2021-01-11 03:21:34 -06:00
.then((res) => res);
2020-11-16 18:53:11 -06:00
};
2021-01-11 03:21:34 -06:00
module.exports = programasAdmin;