listo, faltan correo y pruebas
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
const csv = require('csvtojson');
|
||||
const { eliminarArchivo } = require('../../helper/helper');
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
|
||||
const cargaMasiva = async (file) => {
|
||||
const path = `server/uploads/${file}`;
|
||||
let res = [];
|
||||
|
||||
await csv()
|
||||
.fromFile(path)
|
||||
.then(async (profesores) => {
|
||||
for (let i = 0; i < profesores.length; i++) {
|
||||
const resp = await Profesor.create({
|
||||
numeroTrabajador: profesores[i].numeroTrabajador,
|
||||
nombre: profesores[i].nombre,
|
||||
correo: `${profesores[i].numeroTrabajador}@pcpuma.acatlan.unam.mx`,
|
||||
adscripcion: profesores[i].adscripcion,
|
||||
})
|
||||
res.push(resp)
|
||||
}
|
||||
await eliminarArchivo(path);
|
||||
});
|
||||
return {
|
||||
message: 'Se subió correctamente el archivo csv.',
|
||||
res
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = cargaMasiva;
|
||||
@@ -0,0 +1,22 @@
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
const validar = require('../../helper/validar');
|
||||
|
||||
const entradaInvitado = async (body) => {
|
||||
const idProfesor = validar.validarNumeroEntero(body.idProfesor, 'idProfesor');
|
||||
|
||||
const profesor = await Profesor.findOne({ where: idProfesor });
|
||||
if (!profesor) throw new Error('Este profesor no existe');
|
||||
let noInvDentro = profesor.dataValues.numeroInvitadosDentro;
|
||||
let noInv = profesor.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 });
|
||||
if (!res)
|
||||
throw new Error(
|
||||
'Ha ocurrido un error al actualizar los datos del profesor.'
|
||||
);
|
||||
return res;
|
||||
};
|
||||
|
||||
module.exports = entradaInvitado;
|
||||
Reference in New Issue
Block a user