From 6a79f57102edc0384fe18ad564a402b44095be6d Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Wed, 27 Jul 2022 20:02:46 -0500 Subject: [PATCH] carrera --- server/controller/Usuario/escolares.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/server/controller/Usuario/escolares.js b/server/controller/Usuario/escolares.js index 1d9bc58..f5c229e 100644 --- a/server/controller/Usuario/escolares.js +++ b/server/controller/Usuario/escolares.js @@ -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, }); }); }