Files
inscripciones_api/server/controller/Usuario/escolares.js
T

44 lines
1017 B
JavaScript
Raw Normal View History

const { obtenerDatosUsr } = require('../../config/mariadb.conf');
2022-03-21 14:03:30 -06:00
const {
validarNumeroCuenta,
validarNumeroEntero,
} = require('../../helper/validar');
2022-01-24 14:33:16 -06:00
const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
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-01-26 00:21:54 -06:00
}).then((res) => {
if (!res) {
2022-03-21 14:03:30 -06:00
return obtenerDatosUsr(numeroCuenta).then(async (res) => {
2022-01-30 23:50:17 -06:00
return Usuario.create({
2022-03-21 14:03:30 -06:00
numeroCuenta,
2022-01-30 23:50:17 -06:00
nombre: body.nombre,
generacion: res.generacion,
2022-01-30 23:50:17 -06:00
carrera: body.carrera,
idCarrera: res.id_carrera,
});
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',
'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;