Files
Andres2908 6a79f57102 carrera
2022-07-27 20:02:46 -05:00

51 lines
1.3 KiB
JavaScript

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(
body.numeroCuenta,
'numero cuenta',
true
);
return Usuario.findOne({
where: { numeroCuenta },
}).then(async (res) => {
if (!res) {
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: datosUsuario.generacion,
carrera: body.carrera,
idCarrera: datosUsuario.id_carrera,
});
});
}
return Usuario.findOne({
where: { numeroCuenta },
attributes: [
'idUsuario',
'numeroCuenta',
'nombre',
'generacion',
'idCarrera',
'carrera',
],
});
});
};
module.exports = escolares;