2022-01-02 15:07:49 -06:00
|
|
|
const { validarNumeroEntero } = require('../../helper/validar');
|
2021-05-05 18:49:23 -05:00
|
|
|
const dbPath = '../../db/tablas';
|
|
|
|
|
const Programa = require(`${dbPath}/Programa`);
|
|
|
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
2020-11-16 18:53:11 -06:00
|
|
|
|
2021-01-11 03:21:34 -06:00
|
|
|
const programasResponsable = async (body) => {
|
2022-01-02 15:07:49 -06:00
|
|
|
const idUsuario = validarNumeroEntero(body.idUsuario, 'id usuario');
|
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({
|
2020-11-17 11:39:39 -06:00
|
|
|
where: { idUsuario, activo: true },
|
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 = programasResponsable;
|