Files
inscripciones_api/server/controller/Usuario/escolares.js
T
2022-06-14 18:50:40 -05:00

41 lines
990 B
JavaScript

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