excel primer semestre aparentemente listo

This commit is contained in:
2021-07-18 19:32:41 -05:00
parent 3d3b2836ca
commit 4e9bf1e439
6 changed files with 977 additions and 37 deletions
+59
View File
@@ -0,0 +1,59 @@
const { convertArrayToCSV } = require('convert-array-to-csv');
const moment = require('moment');
const helperPath = '../../helper';
const helper = require(`${helperPath}/helper`);
const encriptar = require(`${helperPath}/encriptar`);
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
const Grupo = require(`${dbPath}/Grupo`);
const Horario = require(`${dbPath}/Horario`);
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
const get = async (body) => {
const path = `server/uploads/primer_semestre.csv`;
const data = [];
if (!body.password) throw new Error('No hay contraseña.');
if (
!encriptar.comparar(
body.password,
'$2b$10$/yZZE6Ee8GEUgCmzCd/mWehpb94g74cmk6fDb52G4W0tQ9Py9M.Ia'
)
)
throw new Error('Contraseña no valida.');
return PrimerSemestre.findAll({
include: [{ model: Grupo, include: [{ model: Carrera }] }],
})
.then(async (res) => {
for (let i = 0; i < res.length; i++) {
const horario = await Horario.findOne({
where: { idHorario: res[i].idHorario },
}).then((res) => moment(res.horario));
data.push({
numeroCuenta: res[i].numeroCuenta,
nombre: res[i].nombre,
carrera: res[i].Grupo.Carrera.carrera,
grupo: res[i].Grupo.grupo,
horario: `${
horario.date() < 10 ? '0' + horario.date() : horario.date()
}/${
horario.month() + 1 < 10
? '0' + (horario.month() + 1)
: horario.month() + 1
}/${horario.year()} ${
horario.hour() < 10 ? '0' + horario.hour() : horario.hour()
}:${
horario.minute() < 10 ? '0' + horario.minute() : horario.minute()
}`,
});
}
await helper.eliminarArchivo(path).catch((err) => {});
return helper.crearArchivo(path, convertArrayToCSV(data));
})
.then((res) => path);
};
module.exports = get;
get({ password: 'hola' });