route y controller de los cuestionarios, aun en desarrollo

This commit is contained in:
Tu Nombre
2025-01-28 12:10:52 -06:00
parent 493fd83e0e
commit d181790277
6 changed files with 417 additions and 11 deletions
+57 -2
View File
@@ -6,12 +6,17 @@ const helper = require(`${helperPath}/helper`);
const { validarNumero } = require(`${helperPath}/validar`);
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
const CuestionarioPrograma = require(`${dbPath}/CuestionarioPrograma`);
const Servicio = require(`${dbPath}/Servicio`);
const Programa = require(`${dbPath}/Programa`);
const Usuario = require(`${dbPath}/Usuario`);
const get = async (body) => {
const CuestionarioPrograma2 = require(`${dbPath}/CuestionarioPrograma`);
const CuestionarioPrograma = require(`${dbPath}/CuestionarioPrograma`);
const getOld = async (body) => {
const year = validarNumero(body.year, 'año', true, 4);
const path = `server/uploads/${year}_cuestionario_programa.csv`;
const data = [];
@@ -56,4 +61,54 @@ const get = async (body) => {
.then((res) => path);
};
const get = async (body) => {
const year = validarNumero(body.year, 'año', true, 4);
const path = `server/uploads/${year}_cuestionario_programa.csv`;
const data = [];
return CuestionarioPrograma2.findAll({
where: {
idCuestionarioPrograma2: {
[Op.not]: null,
},
},
})
.then(async (res) => {
console.log("segunda parte", res);
for (let i = 0; i < res.length; i++) {
data.push(res[i].get({ plain: true }));
}
// Alternativa manual si necesitas campos específicos
/* for (let i = 0; i < res.length; i++) {
const row = res[i].get({ plain: true });
data.push({
idCuestionarioPrograma2: row.idCuestionarioPrograma2,
p1: row.p1,
p2: row.p2,
p3: row.p3,
p4: row.p4,
p5: row.p5,
// Agrega los demás campos según sea necesario
});
} */
await helper.eliminarArchivo(path).catch((err) => {
console.log(err);
});
return helper.crearArchivo(path, convertArrayToCSV(data));
})
.then((res) => path);
}
module.exports = get;