nuevos cuestionarios de programa y alumno, sql de update, falta revisar el proceso de servicio para actualizar el get de los id cuestionarios
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
const fs = require('fs');
|
||||
const { convertArrayToCSV } = require('convert-array-to-csv');
|
||||
const { Op } = require('sequelize');
|
||||
const helperPath = '../../helper';
|
||||
const helper = require(`${helperPath}/helper`);
|
||||
const { validarNumero } = require(`${helperPath}/validar`);
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const CuestionarioPrograma2 = require(`${dbPath}/CuestionarioPrograma`);
|
||||
const Servicio = require(`${dbPath}/Servicio`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* return Servicio.findAll({
|
||||
include: [
|
||||
{
|
||||
model: CuestionarioPrograma,
|
||||
where: { idCuestionarioPrograma: { [Op.not]: null } },
|
||||
},
|
||||
{ model: Programa, where: { clavePrograma: { [Op.like]: `${year}-%` } } },
|
||||
{ model: Usuario },
|
||||
{ model: Carrera },
|
||||
],
|
||||
order: [['createdAt']],
|
||||
})
|
||||
.then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++)
|
||||
data.push({
|
||||
idServicio: res[i].idServicio,
|
||||
clavePrograma: res[i].Programa.clavePrograma,
|
||||
usuario: res[i].Usuario.usuario,
|
||||
nombre: res[i].Usuario.nombre,
|
||||
carrera: res[i].Carrera.carrera,
|
||||
idCuestionarioPrograma:
|
||||
res[i].CuestionarioPrograma.idCuestionarioPrograma,
|
||||
actividad1: res[i].CuestionarioPrograma.actividad1,
|
||||
actividad2: res[i].CuestionarioPrograma.actividad2,
|
||||
actividad3: res[i].CuestionarioPrograma.actividad3,
|
||||
actividad4: res[i].CuestionarioPrograma.actividad4,
|
||||
actividad5: res[i].CuestionarioPrograma.actividad5,
|
||||
retroalimentacion: res[i].CuestionarioPrograma.retroalimentacion,
|
||||
p6: res[i].CuestionarioPrograma.p6,
|
||||
p7: res[i].CuestionarioPrograma.p7,
|
||||
createdAt: res[i].CuestionarioPrograma.createdAt,
|
||||
});
|
||||
await helper.eliminarArchivo(path).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
return helper.crearArchivo(path, convertArrayToCSV(data));
|
||||
})
|
||||
.then((res) => path);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
module.exports = get;
|
||||
Reference in New Issue
Block a user