listo para pruebas
This commit is contained in:
@@ -17,7 +17,8 @@ const obtenerAlumno = async (numeroCuenta) => {
|
||||
.query(`CALL busca_alumno_pcpuma('${numeroCuenta}')`)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
return { rows, length: rows.length };
|
||||
if (rows[0].length === 0) return null;
|
||||
return rows[0][0];
|
||||
})
|
||||
.catch((err) => {
|
||||
conn.end();
|
||||
|
||||
@@ -1,10 +1,44 @@
|
||||
const obtenerAlumno = require('../../config/mariadb.conf');
|
||||
const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
|
||||
const escolares = async (body) => {
|
||||
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
|
||||
return obtenerAlumno(numeroCuenta);
|
||||
return Usuario.findOne({
|
||||
where: { usuario: numeroCuenta },
|
||||
include: [{ model: Carrera }],
|
||||
}).then(async (res) => {
|
||||
let usuario = res;
|
||||
|
||||
if (!usuario) {
|
||||
const alumno = await obtenerAlumno(numeroCuenta);
|
||||
|
||||
if (!alumno) throw new Error('Este alumno no existe o no esta inscrito.');
|
||||
await Carrera.findOne({ where: { carrera: alumno.carrera } })
|
||||
.then(async (res) => {
|
||||
if (!res) return Carrera.create({ carrera: alumno.carrera });
|
||||
return res;
|
||||
})
|
||||
.then((res) =>
|
||||
Usuario.create({
|
||||
usuario: alumno.cuenta,
|
||||
nombre: nombre,
|
||||
idCarrera: res.idCarrera,
|
||||
})
|
||||
)
|
||||
.then((res) =>
|
||||
Usuario.findOne({
|
||||
where: { usuario: numeroCuenta },
|
||||
include: [{ model: Carrera }],
|
||||
})
|
||||
)
|
||||
.then((res) => (usuario = res));
|
||||
}
|
||||
return usuario;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = escolares;
|
||||
|
||||
@@ -99,43 +99,6 @@ const dataTipoUsuario = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const dataCarrera = async () => {
|
||||
const data = [
|
||||
'LIC. EN DERECHO',
|
||||
'LIC. EN ACTUARIA',
|
||||
'LIC. EN MATEMATICAS APLICADAS Y COMP.',
|
||||
'LIC. EN COMUNICACION',
|
||||
'LIC. EN ECONOMIA',
|
||||
'LIC. EN PERIODISMO Y COMUNICACION COL.',
|
||||
'LIC. EN RELACIONES INTERNACIONALES',
|
||||
'LIC. EN FILOSOFIA',
|
||||
'LIC. EN HISTORIA',
|
||||
'LIC. EN LENGUA Y LITERATURA HISPANICAS',
|
||||
'LIC. EN SOCIOLOGIA',
|
||||
'LIC. EN CIENCIAS POLITICAS Y ADMON PUB',
|
||||
'LIC. EN INGENIERIA CIVIL',
|
||||
'LIC. EN ENSEÑANZA DE INGLES',
|
||||
'LIC. EN DISEÑO GRAFICO',
|
||||
'LIC. EN PEDAGOGÍA',
|
||||
'LIC. EN DERECHO (SUA)',
|
||||
'LIC. ENSEÑANZA DE ESPAÑOL(LENG. EXTRANJ)',
|
||||
'LIC. ENSEÑANZA DE ITALIANO(LENG. EXTRANJ',
|
||||
'LIC. EN ARQUITECTURA',
|
||||
'LIC. EN RELACIONES INTERNACIONALES (SUA)',
|
||||
'LIC. ENSEÑANZA DE INGLÉS(LENG. EXTRANJE)',
|
||||
'LIC. ENSEÑANZA DE ALEMÁN (LENG. EXTRANJS',
|
||||
'LIC. EN MAT. APLICADAS Y COMPUTACION',
|
||||
];
|
||||
|
||||
console.log('\nPaso 4) Insertando data carrera.'.bold.blue);
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
await Carrera.create({
|
||||
carrera: data[i],
|
||||
});
|
||||
console.log(`Se agrego la carrera ${data[i]}.`.magenta);
|
||||
}
|
||||
};
|
||||
|
||||
const dataModulo = async () => {
|
||||
const data = ['MAC', 'Derecho'];
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ Usuario.init(
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING(60),
|
||||
allowNull: false,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
nombre: {
|
||||
type: DataTypes.STRING(70),
|
||||
@@ -28,7 +29,8 @@ Usuario.init(
|
||||
},
|
||||
telefono: {
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: false,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
multa: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
|
||||
Reference in New Issue
Block a user