api completa

This commit is contained in:
2022-05-13 22:10:54 -05:00
parent f9fa0ac0ca
commit 2015de3729
31 changed files with 366 additions and 89 deletions
+2 -1
View File
@@ -10,7 +10,8 @@ const adscripciones = async () => {
result.push(item.adscripcion);
}
});
return result
return result;
});
};
module.exports = adscripciones;
+14 -5
View File
@@ -1,8 +1,11 @@
const csv = require('csvtojson');
const { eliminarArchivo } = require('../../helper/helper');
const Profesor = require('../../db/tablas/Profesor');
const { validarNumeroEntero } = require('../../helper/validar');
const ProfesorPremiacion = require('../../db/tablas/profesorPremiacion');
const cargaMasiva = async (file) => {
const cargaMasiva = async (file, body) => {
const idPremiacion = validarNumeroEntero(body.idPremiacion);
const path = `server/uploads/${file}`;
let res = [];
@@ -15,15 +18,21 @@ const cargaMasiva = async (file) => {
nombre: profesores[i].nombre,
correo: `${profesores[i].numeroTrabajador}@pcpuma.acatlan.unam.mx`,
adscripcion: profesores[i].adscripcion,
})
res.push(resp)
});
res.push(resp);
await ProfesorPremiacion.create({
idPremiacion,
idProfesor: resp.idProfesor,
numeroInvitados: null,
numeroInvitadosDentro: null,
});
}
await eliminarArchivo(path);
});
return {
message: 'Se subió correctamente el archivo csv.',
res
res,
};
};
module.exports = cargaMasiva;
module.exports = cargaMasiva;
+22 -6
View File
@@ -1,21 +1,37 @@
const Profesor = require('../../db/tablas/Profesor');
const ProfesorPremiacion = require('../../db/tablas/ProfesorPremiacion');
const validar = require('../../helper/validar');
const entradaInvitado = async (body) => {
const idProfesor = validar.validarNumeroEntero(body.idProfesor, 'idProfesor');
const idPremiacion = validar.validarNumeroEntero(
body.idPremiacion,
'idPremiacion'
);
const profesor = await Profesor.findOne({ where: idProfesor });
if (!profesor) throw new Error('Este profesor no existe');
if (!profesor.noInvitados) throw new Error('Este profesor no registró a ninún invitado.')
let noInvDentro = profesor.dataValues.numeroInvitadosDentro;
let noInv = profesor.dataValues.numeroInvitados;
if (!profesor) throw new Error('Este profesor no existe.');
const profPrem = await ProfesorPremiacion.findOne({
where: { idPremiacion, idProfesor },
});
if (!profPrem)
throw new Error(
'Este profesor no está registrado en esta entrega de medallas.'
);
if (!profPrem.numeroInvitados)
throw new Error('Este profesor no registró a ninún invitado.');
let noInvDentro = profPrem.dataValues.numeroInvitadosDentro;
let noInv = profPrem.dataValues.numeroInvitados;
if (noInvDentro && noInvDentro >= noInv)
throw new Error('Este profesor ya ingreso a todos sus invitados.');
const res = await profesor.update({ numeroInvitadosDentro: noInvDentro + 1 });
const res = await profPrem.update({ numeroInvitadosDentro: noInvDentro + 1 });
if (!res)
throw new Error(
'Ha ocurrido un error al actualizar los datos del profesor.'
'Ha ocurrido un error al registrar los invitados del profesor.'
);
return res;
};
+9 -7
View File
@@ -8,15 +8,17 @@ const login = async (body) => {
'numero de trabajador',
true
);
const adscripcion = validar.validacionBasicaStr(
body.adscripcion,
'adscripcion',
false,
150
);
// const adscripcion = validar.validacionBasicaStr(
// body.adscripcion,
// 'adscripcion',
// false,
// 150
// );
return Profesor.findOne({
where: { numeroTrabajador, adscripcion },
where: { numeroTrabajador
// , adscripcion
},
}).then((res) => {
if (!res) throw new Error('No existe este profesor en la base de datos.');
return {