Files
inscripciones_api/server/controller/Usuario/escolares.js
T
2022-03-15 00:23:09 -06:00

40 lines
1.1 KiB
JavaScript

const { obtenerDatosUsr } = require('../../config/mariadb.conf');
const { validarNumeroEntero } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
const Usuario = require(`${dbPath}/Usuario`);
const escolares = async (body) => {
const idUsuario = validarNumeroEntero(body.idUsuario, 'id Usuario', true);
return Usuario.findOne({
where: { numeroCuenta: body.numeroCuenta },
}).then((res) => {
if (!res) {
return obtenerDatosUsr(body.numeroCuenta).then(async (res) => {
return Usuario.create({
idUsuario,
numeroCuenta: body.numeroCuenta,
nombre: body.nombre,
generacion: res.generacion,
carrera: body.carrera,
idCarrera: res.id_carrera,
});
});
}
return Usuario.findOne({
where: { numeroCuenta: body.numeroCuenta },
attributes: [
'idUsuario',
'numeroCuenta',
'nombre',
'generacion',
'idCarrera',
'carrera',
],
});
});
};
module.exports = escolares;