listo, faltan correo y pruebas

This commit is contained in:
2022-04-17 22:23:39 -05:00
parent de238e3e50
commit a69574d529
23 changed files with 695 additions and 62 deletions
+29
View File
@@ -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;