Mensajes y corregí errores en el login

This commit is contained in:
Andres2908
2022-01-30 23:50:17 -06:00
parent 494e7380f3
commit f591727f82
6 changed files with 30 additions and 14 deletions
+4 -4
View File
@@ -8,13 +8,13 @@ const pool = mariadb.createPool({
database: process.env.SAT_DB,
});
const obtenerAlumno = async (numeroCuenta) => {
const obtenerIdCarrera = async (numeroCuenta) => {
const conn = await pool.getConnection().catch((err) => {
throw new Error('No se pudo conectar con la db. ' + err);
});
return conn
.query(`SELECT *FROM alumno WHERE id_cuenta = ${numeroCuenta}`)
.query(`SELECT id_carrera FROM alumno WHERE id_cuenta = ${numeroCuenta}`)
.then((rows) => {
conn.end();
// console.log(rows[0]);
@@ -33,7 +33,7 @@ const obtenerCarrera = async (idCarrera) => {
});
return conn
.query(`SELECT *FROM carrera WHERE id_carrera = ${idCarrera}`)
.query(`SELECT id_carrera FROM carrera WHERE id_carrera = ${idCarrera}`)
.then((rows) => {
conn.end();
return rows[0];
@@ -44,4 +44,4 @@ const obtenerCarrera = async (idCarrera) => {
});
};
module.exports = { obtenerAlumno, obtenerCarrera };
module.exports = { obtenerIdCarrera, obtenerCarrera };
+14 -7
View File
@@ -1,4 +1,7 @@
const { obtenerAlumno, obtenerCarrera } = require('../../config/mariadb.conf');
const {
obtenerIdCarrera,
obtenerCarrera,
} = require('../../config/mariadb.conf');
const validar = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
@@ -11,12 +14,15 @@ const escolares = async (body) => {
where: { numeroCuenta: body.numeroCuenta },
}).then((res) => {
if (!res) {
return Usuario.create({
idUsuario: body.idUsuario,
numeroCuenta: body.numeroCuenta,
nombre: body.nombre,
semestre: 8,
carrera: body.carrera,
return obtenerIdCarrera(body.numeroCuenta).then(async (res) => {
return Usuario.create({
idUsuario: body.idUsuario,
numeroCuenta: body.numeroCuenta,
nombre: body.nombre,
semestre: 8,
carrera: body.carrera,
idCarrera: res.id_carrera,
});
});
}
return Usuario.findOne({
@@ -27,6 +33,7 @@ const escolares = async (body) => {
'numeroCuenta',
'nombre',
'semestre',
'idCarrera',
'carrera',
],
});
@@ -21,7 +21,9 @@ const inscripcion = async (body) => {
fechaIncripcion: ahora.format(),
fechaTicket: body.fechaTicket,
idFechaInscripcion: body.idFechaInscripcion,
});
}).then((res) => ({
message: '¡La inscripción se realizo de manera correcta!',
}));
};
module.exports = inscripcion;
+2 -1
View File
@@ -8,7 +8,8 @@ const inscripciones = async (body) => {
return Inscripcion.findOne({
where: { idUsuario: body.idUsuario },
}).then((res) => {
if (!res) return;
console.log(res);
if (!res) return [];
return Inscripcion.findAll({
where: { idUsuario: body.idUsuario },
attributes: [
+3 -1
View File
@@ -18,12 +18,14 @@ const login = async (body) => {
)
.then((res) => {
const info = res.data;
console.log('res.data');
// console.log(res.data);
info.data.numeroCuenta = numeroCuenta;
const datos = escolares(info.data);
return datos;
})
.catch((err) => {
console.log(err);
throw new Error('Usuario o contraseña incorrecta.' + err);
});
};
+4
View File
@@ -26,6 +26,10 @@ Usuario.init(
type: DataTypes.STRING(30),
allowNull: false,
},
idCarrera: {
type: DataTypes.INTEGER,
allowNull: false,
},
carrera: {
type: DataTypes.STRING(60),
allowNull: false,