listo para pruebas

This commit is contained in:
Lemuel Marquez
2021-05-19 02:34:45 -05:00
parent f27f497433
commit 09bfbf7f85
4 changed files with 41 additions and 41 deletions
+35 -1
View File
@@ -1,10 +1,44 @@
const obtenerAlumno = require('../../config/mariadb.conf');
const validar = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
const Carrera = require(`${dbPath}/Carrera`);
const escolares = async (body) => {
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
return obtenerAlumno(numeroCuenta);
return Usuario.findOne({
where: { usuario: numeroCuenta },
include: [{ model: Carrera }],
}).then(async (res) => {
let usuario = res;
if (!usuario) {
const alumno = await obtenerAlumno(numeroCuenta);
if (!alumno) throw new Error('Este alumno no existe o no esta inscrito.');
await Carrera.findOne({ where: { carrera: alumno.carrera } })
.then(async (res) => {
if (!res) return Carrera.create({ carrera: alumno.carrera });
return res;
})
.then((res) =>
Usuario.create({
usuario: alumno.cuenta,
nombre: nombre,
idCarrera: res.idCarrera,
})
)
.then((res) =>
Usuario.findOne({
where: { usuario: numeroCuenta },
include: [{ model: Carrera }],
})
)
.then((res) => (usuario = res));
}
return usuario;
});
};
module.exports = escolares;