41 lines
990 B
JavaScript
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;
|