2022-03-15 00:23:09 -06:00
|
|
|
const { obtenerDatosUsr } = require('../../config/mariadb.conf');
|
2022-06-14 18:50:40 -05:00
|
|
|
const { validarNumeroCuenta } = require('../../helper/validar');
|
2022-01-24 14:33:16 -06:00
|
|
|
const dbPath = '../../db/tablas';
|
|
|
|
|
const Usuario = require(`${dbPath}/Usuario`);
|
2022-07-27 20:02:46 -05:00
|
|
|
const Carrera = require(`${dbPath}/Carrera`);
|
2022-01-24 14:33:16 -06:00
|
|
|
|
|
|
|
|
const escolares = async (body) => {
|
2022-03-21 14:03:30 -06:00
|
|
|
const numeroCuenta = validarNumeroCuenta(
|
|
|
|
|
body.numeroCuenta,
|
|
|
|
|
'numero cuenta',
|
|
|
|
|
true
|
|
|
|
|
);
|
2022-01-24 14:33:16 -06:00
|
|
|
return Usuario.findOne({
|
2022-03-21 14:03:30 -06:00
|
|
|
where: { numeroCuenta },
|
2022-07-27 20:02:46 -05:00
|
|
|
}).then(async (res) => {
|
2022-01-26 00:21:54 -06:00
|
|
|
if (!res) {
|
2022-07-27 20:02:46 -05:00
|
|
|
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({
|
2022-03-21 14:03:30 -06:00
|
|
|
numeroCuenta,
|
2022-01-30 23:50:17 -06:00
|
|
|
nombre: body.nombre,
|
2022-07-27 20:02:46 -05:00
|
|
|
generacion: datosUsuario.generacion,
|
2022-01-30 23:50:17 -06:00
|
|
|
carrera: body.carrera,
|
2022-07-27 20:02:46 -05:00
|
|
|
idCarrera: datosUsuario.id_carrera,
|
2022-01-30 23:50:17 -06:00
|
|
|
});
|
2022-01-27 00:15:05 -06:00
|
|
|
});
|
2022-01-26 00:21:54 -06:00
|
|
|
}
|
|
|
|
|
return Usuario.findOne({
|
2022-03-21 14:03:30 -06:00
|
|
|
where: { numeroCuenta },
|
2022-01-27 00:15:05 -06:00
|
|
|
attributes: [
|
|
|
|
|
'idUsuario',
|
|
|
|
|
'numeroCuenta',
|
|
|
|
|
'nombre',
|
2022-03-15 00:23:09 -06:00
|
|
|
'generacion',
|
2022-01-30 23:50:17 -06:00
|
|
|
'idCarrera',
|
2022-01-27 00:15:05 -06:00
|
|
|
'carrera',
|
|
|
|
|
],
|
2022-01-24 14:33:16 -06:00
|
|
|
});
|
2022-01-26 00:21:54 -06:00
|
|
|
});
|
2022-01-24 14:33:16 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = escolares;
|