listo para pruebas
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user