responder con el archivo en los reportes
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user