Files
inscripciones_api/server/controller/Usuario/escolares.js
T
2022-03-07 09:31:12 -06:00

41 lines
1.0 KiB
JavaScript

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