Files

91 lines
3.6 KiB
JavaScript
Raw Permalink Normal View History

2020-11-16 09:58:55 -06:00
require('../../config/config');
const axios = require('axios');
2021-05-13 14:06:07 -05:00
const { validarNumeroCuenta } = require('../../helper/validar');
2021-05-05 18:49:23 -05:00
const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
const Carrera = require(`${dbPath}/Carrera`);
2021-08-04 10:20:12 -05:00
const creditosCarreras = [
2022-11-17 19:01:51 -06:00
{ carrera: 'LIC. EN ACTUARIA', creditos: 64 },
2021-08-04 10:20:12 -05:00
{ carrera: 'LIC. EN ARQUITECTURA', creditos: 70 },
2023-02-09 17:11:16 -06:00
{ carrera: 'LIC. EN CIENCIAS POLITICAS Y ADMON PUB', creditos: 67 },
{ carrera: 'LIC. EN CIENCIAS POLITICAS Y ADMON.PUBL.', creditos: 67 },
{ carrera: 'LIC. EN COMUNICACION', creditos: 67 },
2022-11-17 19:01:51 -06:00
{ carrera: 'LIC. EN DERECHO', creditos: 68 },
{ carrera: 'LIC. EN DERECHO (SUA)', creditos: 67 },
2021-08-04 10:20:12 -05:00
{ carrera: 'LIC. EN DISEÑO GRAFICO', creditos: 70 },
2023-02-09 17:11:16 -06:00
{ carrera: 'LIC. EN ECONOMIA', creditos: 66 },
{ carrera: 'LIC. EN ENSEÑANZA DE INGLES', creditos: 69 },
2021-08-04 10:20:12 -05:00
{ carrera: 'LIC. EN FILOSOFIA', creditos: 70 },
{ carrera: 'LIC. EN HISTORIA', creditos: 70 },
{ carrera: 'LIC. EN INGENIERIA CIVIL', creditos: 70 },
{ carrera: 'LIC. EN LENGUA Y LITERATURA HISPANICAS', creditos: 70 },
2022-11-17 19:01:51 -06:00
{ carrera: 'LIC. EN MAT. APLICADAS Y COMPUTACION', creditos: 66 },
{ carrera: 'LIC. EN MATEMATICAS APLICADAS Y COMP.', creditos: 66 },
2021-08-04 10:20:12 -05:00
{ carrera: 'LIC. EN PEDAGOGÍA', creditos: 70 },
{ carrera: 'LIC. EN PERIODISMO Y COMUNICACION COL.', creditos: 70 },
{ carrera: 'LIC. EN RELACIONES INTERNACIONALES', creditos: 70 },
{ carrera: 'LIC. EN RELACIONES INTERNACIONALES (SUA)', creditos: 70 },
2022-11-17 19:01:51 -06:00
{ carrera: 'LIC. EN SOCIOLOGIA', creditos: 68 },
2021-08-04 10:20:12 -05:00
{ carrera: 'LIC. ENSEÑANZA DE ALEMÁN (LENG. EXTRANJS', creditos: 70 },
{ carrera: 'LIC. ENSEÑANZA DE ESPAÑOL(LENG. EXTRANJ)', creditos: 70 },
{ carrera: 'LIC. ENSEÑANZA DE INGLÉS(LENG. EXTRANJE)', creditos: 70 },
{ carrera: 'LIC. ENSEÑANZA DE ITALIANO(LENG. EXTRANJ', creditos: 70 },
];
2020-11-16 09:58:55 -06:00
const escolares = async (body) => {
2021-05-13 14:06:07 -05:00
const numeroCuenta = validarNumeroCuenta(body.numeroCuenta);
2020-11-16 09:58:55 -06:00
let alumno;
2021-02-15 15:11:32 -06:00
return axios({
method: 'post',
url: `${process.env.ESCOLARES}${numeroCuenta}`,
data: `${process.env.ESCOLARES_PASS}`,
})
2020-11-16 09:58:55 -06:00
.then((res) => {
2021-02-15 15:11:32 -06:00
if (!res.data.nombre || !res.data.carrconst || !res.data.avance)
2020-11-16 09:58:55 -06:00
throw new Error(
'El alumno no cumple con los requisitos para realizar el Servicio Social. Si cree que esto es erróneo comunícate al Departamento de Servicio Social y Bolsa de Trabajo.'
2020-11-16 09:58:55 -06:00
);
alumno = {
2021-02-15 15:11:32 -06:00
nombre: res.data.nombre.trim(),
creditos: res.data.avance,
carrera: res.data.carrconst.trim(),
2020-11-16 09:58:55 -06:00
};
2021-08-04 10:20:12 -05:00
for (let i = 0; i < creditosCarreras.length; i++)
if (
alumno.carrera === creditosCarreras[i].carrera &&
Number(alumno.creditos) < creditosCarreras[i].creditos
)
throw new Error('Este alumno no cuenta con los créditos necesarios.');
2021-04-17 10:20:11 -05:00
while (
alumno.nombre.search('‘') != -1 &&
alumno.nombre.search('Ã') != -1
) {
alumno.nombre = alumno.nombre.replace('Ã', 'Ñ');
alumno.nombre = alumno.nombre.replace('‘', '');
2021-04-17 10:17:54 -05:00
}
2020-11-16 12:47:46 -06:00
return Carrera.findOne({ where: { carrera: alumno.carrera } });
})
.then((res) => {
if (!res) return Carrera.create({ carrera: alumno.carrera });
return res;
})
.then((res) => {
alumno.idCarrera = res.idCarrera;
2020-11-16 09:58:55 -06:00
return Usuario.findOne({ where: { usuario: numeroCuenta } });
})
.then((res) => {
if (!res)
return Usuario.create({
usuario: numeroCuenta,
activo: false,
2020-11-17 17:27:12 -06:00
nombre: alumno.nombre,
2020-11-16 09:58:55 -06:00
idTipoUsuario: 3,
});
return res;
})
2021-01-14 16:02:57 -06:00
.then((res) => ({ ...alumno, idUsuario: res.idUsuario }));
2020-11-16 09:58:55 -06:00
};
module.exports = escolares;