Files
pcpuma_acatlan_api/server/controller/Usuario/usuario.js
T
2021-05-20 14:32:48 -05:00

25 lines
802 B
JavaScript

const { Op } = require('sequelize');
const validar = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
const Carrera = require(`${dbPath}/Carrera`);
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
const usuario = async (body) => {
const usuario = validar.validarNumeroCuenta(body.usuario);
return Usuario.findOne({
where: { usuario, password: { [Op.ne]: null } },
include: [{ model: TipoUsuario }, { model: Carrera }],
}).then((res) => {
if (!res) throw new Error('No existe este usuario.');
delete res.dataValues.password;
delete res.dataValues.idTipoUsuario;
if (!res.idCarrera) delete res.dataValues.Carrera;
delete res.dataValues.idCarrera;
return res;
});
};
module.exports = usuario;