aparentemente listo conexión profesores
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const obtenerAlumno = require('../../config/mariadb.conf');
|
||||
const { obtenerAlumno, obtenerProfesor } = require('../../config/mariadb.conf');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
@@ -14,29 +14,47 @@ const escolares = async (body) => {
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) {
|
||||
let alumno = {};
|
||||
let usuario = {};
|
||||
let esAlumno = false;
|
||||
|
||||
return obtenerAlumno(numeroCuenta)
|
||||
.then(async (res) => {
|
||||
alumno = res;
|
||||
if (!alumno)
|
||||
throw new Error('Este alumno no existe o no esta inscrito.');
|
||||
if (alumno.inscrito != 'SI')
|
||||
throw new Error('Este alumno no esta inscrito este semestre.');
|
||||
return Carrera.findOne({ where: { carrera: alumno.carrera } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) return Carrera.create({ carrera: alumno.carrera });
|
||||
if (!res) return obtenerProfesor(numeroCuenta);
|
||||
esAlumno = true;
|
||||
return res;
|
||||
})
|
||||
.then((res) =>
|
||||
Usuario.create({
|
||||
.then(async (res) => {
|
||||
usuario = res;
|
||||
if (!usuario)
|
||||
throw new Error(
|
||||
'Este número de cuenta o de trabajador no existe.'
|
||||
);
|
||||
if (esAlumno) {
|
||||
if (usuario.inscrito != 'SI')
|
||||
throw new Error('Este alumno no esta inscrito este semestre.');
|
||||
await Carrera.findOne({
|
||||
where: { carrera: usuario.carrera },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) return Carrera.create({ carrera: usuario.carrera });
|
||||
return res;
|
||||
})
|
||||
.then((res) => {
|
||||
usuario.Carrera = res;
|
||||
usuario.nombre = usuario.nombre.trim();
|
||||
usuario.idTipoUsuario = 4;
|
||||
});
|
||||
} else {
|
||||
usuario.idTipoUsuario = 3;
|
||||
usuario.nombre = `${usuario.a_paterno.trim()} ${usuario.a_materno.trim()} ${usuario.nombre.trim()}`;
|
||||
}
|
||||
return Usuario.create({
|
||||
usuario: numeroCuenta,
|
||||
nombre: alumno.nombre.trim(),
|
||||
idCarrera: res.idCarrera,
|
||||
idTipoUsuario: 4,
|
||||
})
|
||||
)
|
||||
nombre: usuario.nombre,
|
||||
idCarrera: usuario.Carrera.idCarrera,
|
||||
idTipoUsuario: usuario.idTipoUsuario,
|
||||
});
|
||||
})
|
||||
.then((res) =>
|
||||
Usuario.findOne({
|
||||
where: { usuario: numeroCuenta },
|
||||
|
||||
Reference in New Issue
Block a user