This commit is contained in:
Andres2908
2022-07-27 20:02:46 -05:00
parent de3046936f
commit 6a79f57102
+15 -5
View File
@@ -2,6 +2,7 @@ const { obtenerDatosUsr } = require('../../config/mariadb.conf');
const { validarNumeroCuenta } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
const Carrera = require(`${dbPath}/Carrera`);
const escolares = async (body) => {
const numeroCuenta = validarNumeroCuenta(
@@ -11,15 +12,24 @@ const escolares = async (body) => {
);
return Usuario.findOne({
where: { numeroCuenta },
}).then((res) => {
}).then(async (res) => {
if (!res) {
return obtenerDatosUsr(numeroCuenta).then(async (res) => {
await Usuario.create({
const datosUsuario = await obtenerDatosUsr(numeroCuenta);
return Carrera.findOne({
where: { idCarrera: datosUsuario.id_carrera },
}).then(async (res) => {
if (!res) {
await Carrera.create({
idCarrera: datosUsuario.id_carrera,
carrera: body.carrera,
});
}
return Usuario.create({
numeroCuenta,
nombre: body.nombre,
generacion: res.generacion,
generacion: datosUsuario.generacion,
carrera: body.carrera,
idCarrera: res.id_carrera,
idCarrera: datosUsuario.id_carrera,
});
});
}