Files
pcpuma_acatlan_api/server/controller/Usuario/usuario.js
T

25 lines
802 B
JavaScript
Raw Normal View History

const { Op } = require('sequelize');
2021-04-28 00:21:24 -05:00
const validar = require('../../helper/validar');
2021-05-03 23:38:03 -05:00
const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
const Carrera = require(`${dbPath}/Carrera`);
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
2021-04-28 00:21:24 -05:00
2021-05-04 00:32:04 -05:00
const usuario = async (body) => {
2021-04-28 00:21:24 -05:00
const usuario = validar.validarNumeroCuenta(body.usuario);
return Usuario.findOne({
where: { usuario, password: { [Op.ne]: null } },
2021-04-28 00:21:24 -05:00
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;
2021-04-28 00:21:24 -05:00
delete res.dataValues.idCarrera;
return res;
});
};
2021-05-04 00:32:04 -05:00
module.exports = usuario;