responder con el archivo en los reportes

This commit is contained in:
Lemuel Marquez
2021-05-12 19:08:28 -05:00
parent eb2313d671
commit f7c6b7a334
10 changed files with 187 additions and 146 deletions
+18 -20
View File
@@ -12,7 +12,7 @@ const gustavoBazPrada = async (body) => {
const year = validar.validarNumero(body.year, 4);
const inicio = moment(`${year}-01-31`);
const fin = moment(`${parseInt(year) + 1}-01-31`);
const path = `csv/${year}_gustavo_baz_prada.csv`;
const path = `server/uploads/${year}_gustavo_baz_prada.csv`;
const data = [];
return Servicio.findAll({
@@ -23,27 +23,25 @@ const gustavoBazPrada = async (body) => {
],
},
include: [{ model: Usuario }, { model: Carrera }],
}).then((res) => {
for (let i = 0; i < res.length; i++)
data.push({
numeroCuenta: res[i].Usuario.usuario,
nombre: res[i].Usuario.nombre,
licenciatura: res[i].Carrera.carrera,
correo: res[i].correo,
fechaLiberacion: validar.crearDDMMAAAA(res[i].fechaLiberacion),
order: [['fechaLiberacion']],
})
.then(async (res) => {
for (let i = 0; i < res.length; i++)
data.push({
numeroCuenta: res[i].Usuario.usuario,
nombre: res[i].Usuario.nombre,
licenciatura: res[i].Carrera.carrera,
correo: res[i].correo,
fechaLiberacion: validar.crearDDMMAAAA(res[i].fechaLiberacion),
});
await validar.eliminarArchivo(path).catch((err) => {
console.log(err);
});
try {
fs.unlinkSync(path);
} catch (err) {
console.log(err);
}
fs.appendFile(path, convertArrayToCSV(data), (err) => {
if (err) throw new Error(err);
return validar.crearArchivo(path, convertArrayToCSV(data));
})
.then((res) => {
return path;
});
return {
message: `Se creo/actualizo correctamente el csv del reporte Gustavo Baz Prada.`,
};
});
};
module.exports = gustavoBazPrada;
+28 -30
View File
@@ -12,14 +12,14 @@ const Usuario = require(`${dbPath}/Usuario`);
const reporte = async (body) => {
const inicio = validar.validarFecha(body.inicio);
const fin = validar.validarFecha(body.fin);
const path = `csv/reporte.csv`;
const path = `server/uploads/reporte.csv`;
const data = [];
return Servicio.findAll({
where: {
[Op.and]: [
{ fechaInicio: { [Op.gte]: inicio } },
{ fechaInicio: { [Op.lte]: fin } },
{ fechaInicio: { [Op.gte]: inicio.format() } },
{ fechaInicio: { [Op.lte]: fin.format() } },
],
},
include: [
@@ -28,35 +28,33 @@ const reporte = async (body) => {
{ model: Carrera },
{ model: Status },
],
}).then((res) => {
for (let i = 0; i < res.length; i++)
data.push({
numeroCuenta: res[i].Usuario.usuario,
nombre: res[i].Usuario.nombre,
licenciatura: res[i].Carrera.carrera,
correo: res[i].correo,
fechaInicio: validar.crearDDMMAAAA(res[i].fechaInicio),
fechaFin: validar.crearDDMMAAAA(res[i].fechaFin),
fechaLiberacion: validar.crearDDMMAAAA(res[i].fechaLiberacion),
institucion: res[i].Programa.institucion,
dependencia: res[i].Programa.dependencia,
programa: res[i].Programa.programa,
profesor: res[i].profesor,
clave: res[i].Programa.clavePrograma,
status: res[i].Status.status,
order: [['fechaInicio']],
})
.then(async (res) => {
for (let i = 0; i < res.length; i++)
data.push({
numeroCuenta: res[i].Usuario.usuario,
nombre: res[i].Usuario.nombre,
licenciatura: res[i].Carrera.carrera,
correo: res[i].correo,
fechaInicio: validar.crearDDMMAAAA(res[i].fechaInicio),
fechaFin: validar.crearDDMMAAAA(res[i].fechaFin),
fechaLiberacion: validar.crearDDMMAAAA(res[i].fechaLiberacion),
institucion: res[i].Programa.institucion,
dependencia: res[i].Programa.dependencia,
programa: res[i].Programa.programa,
profesor: res[i].profesor,
clave: res[i].Programa.clavePrograma,
status: res[i].Status.status,
});
await validar.eliminarArchivo(path).catch((err) => {
console.log(err);
});
try {
fs.unlinkSync(path);
} catch (err) {
console.log(err);
}
fs.appendFile(path, convertArrayToCSV(data), (err) => {
if (err) throw new Error(err);
return validar.crearArchivo(path, convertArrayToCSV(data));
})
.then((res) => {
return path;
});
return {
message: `Se creo/actualizo correctamente el csv del reporte de servicios sociales.`,
};
});
};
module.exports = reporte;