reduccion de lineas de codigo

This commit is contained in:
Lemuel Marquez
2021-01-14 03:13:37 -06:00
parent 5de85194fe
commit 0de481b596
32 changed files with 182 additions and 1553 deletions
@@ -8,8 +8,9 @@ const Programa = require('../../db/tablas/Programa');
const Usuario = require('../../db/tablas/Usuario');
const get = async (body) => {
let year = validar.validarNumero(body.year, 4);
let path = `csv/${year}_cuestionario_programa.csv`;
const year = validar.validarNumero(body.year, 4);
const path = `csv/${year}_cuestionario_programa.csv`;
const data = [];
return Servicio.findAll({
include: [
@@ -21,9 +22,6 @@ const get = async (body) => {
{ model: Usuario },
],
}).then((res) => {
let data = [];
let csvString = '';
for (let i = 0; i < res.length; i++)
data.push({
idServicio: res[i].idServicio,
@@ -44,13 +42,14 @@ const get = async (body) => {
});
try {
fs.unlinkSync(path);
} catch (err) {}
csvString = convertArrayToCSV(data);
fs.appendFile(path, csvString, (err) => {
} catch (err) {
throw new Error(err);
}
fs.appendFile(path, convertArrayToCSV(data), (err) => {
if (err) throw new Error(err);
});
return {
message: `Se creo/actualizo correctamente el csv del cuestionario de programa del año ${year}`,
message: `Se creo/actualizo correctamente el csv del cuestionario de programa del año ${year}.`,
};
});
};