reportes y correcion de termino

This commit is contained in:
Lemuel Marquez
2021-04-05 15:24:18 -05:00
parent 9b5eeb9b93
commit 871d121cbd
8 changed files with 95 additions and 3272 deletions
+18 -3194
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,44 @@
const fs = require('fs');
const moment = require('moment');
const { convertArrayToCSV } = require('convert-array-to-csv');
const { Op } = require('sequelize');
const validar = require('../../helper/validar');
const Servicio = require('../../db/tablas/Servicio');
const Usuario = require('../../db/tablas/Usuario');
const Carrera = require('../../db/tablas/Carrera');
const gustavoBazPrada = async (body) => {
const year = validar.validarNumero(body.year, 4);
const path = `csv/${year}_gustavo_baz_prada.csv`;
const data = [];
return Servicio.findAll({
where: {
fechaLiberacion: { [Op.gte]: moment(`${year}-01-31`) },
fechaLiberacion: { [Op.lte]: moment(`${year + 1}-01-31`) },
},
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: res[i].fechaLiberacion,
});
try {
fs.unlinkSync(path);
} catch (err) {
console.log(err);
}
fs.appendFile(path, convertArrayToCSV(data), (err) => {
if (err) throw new Error(err);
});
return {
message: `Se creo/actualizo correctamente el csv del reporte Gustavo Baz Prada.`,
};
});
};
module.exports = gustavoBazPrada;
+2 -2
View File
@@ -8,7 +8,7 @@ const Programa = require('../../db/tablas/Programa');
const liberacion = async (body) => {
const idServicio = validar.validarId(body.idServicio);
const update = { idStatus: 6 };
const update = { idStatus: 6, fechaLiberacion: moment() };
let correo = {};
return Servicio.findOne({
@@ -51,7 +51,7 @@ const liberacion = async (body) => {
})
.then((res) =>
Servicio.update(update, {
where: { idServicio, fechaLiberacion: moment() },
where: { idServicio },
})
)
.then((res) => ({
+3 -2
View File
@@ -7,7 +7,7 @@ const Programa = require('../../db/tablas/Programa');
const Usuario = require('../../db/tablas/Usuario');
const Carrera = require('../../db/tablas/Carrera');
const get = async (body) => {
const reporte = async (body) => {
const inicio = validar.validarFecha(body.inicio);
const fin = validar.validarFecha(body.fin);
const path = `csv/reporte.csv`;
@@ -28,6 +28,7 @@ const get = async (body) => {
correo: res[i].correo,
fehcaInicio: res[i].fechaInicio,
fechaFin: res[i].fechaFin,
fechaLiberacion: res[i].fechaLiberacion,
institucion: res[i].Programa.institucion,
dependencia: res[i].Programa.dependencia,
programa: res[i].Programa.programa,
@@ -47,4 +48,4 @@ const get = async (body) => {
});
};
module.exports = get;
module.exports = reporte;
-45
View File
@@ -1,45 +0,0 @@
const moment = require('moment');
const Servicio = require('./tablas/Servicio');
const lastYear = moment('2021-01-31');
const fechaLiberacion = async () => {
Servicio.findAll({ where: { idStatus: 6 } })
.then(async (res) => {
let contador = [0, 0];
for (let i = 0; i < res.length; i++) {
let lastUpdate = moment(res[i].fechaLiberacion);
if (lastUpdate <= lastYear) {
// await Servicio.update(
// { fechaLiberacion: lastYear },
// { where: { idServicio: res[i].idServicio } }
// );
// console.log(
// `El servicio con id ${res[i].idServicio} fue actualizado el ${res[i].updatedAt} año pasado`
// );
contador[0]++;
} else {
// await Servicio.update(
// { fechaLiberacion: lastUpdate },
// { where: { idServicio: res[i].idServicio } }
// );
// console.log(
// `El servicio con id ${res[i].idServicio} fue actualizado el ${res[i].updatedAt} siguiente año`
// );
contador[1]++;
}
}
console.log(contador);
})
.catch((err) => {
console.log(err);
});
};
fechaLiberacion();
/*
ALTER TABLE servicio ADD fechaLiberacion datetime
asignar fecha de liberacipon a servicios liberados
*/
+1 -16
View File
@@ -152,19 +152,4 @@ const exe = async () => {
process.exit();
};
// exe();
const exeCasosEspeciales = async () => {
await CasoEspecial.sync();
console.log('La tabla CasoEspecial se instalo correctamente.'.magenta);
await dataResponsableCasoEspecial();
console.log(
'\nSe ha instalado exitosamente la base de datos.\n'.underline.bold.green
);
process.exit();
};
exeCasosEspeciales();
exe();
+7
View File
@@ -136,6 +136,12 @@ const validarPreTermino = (idServicio) => {
});
};
const validarAccesibilidad = (usuariosValidos = [], idTipoUsuario) => {
for (let i = 0; i < usuariosValidos.length; i++)
if (idTipoUsuario === usuariosValidos[i]) return;
throw new Error('Este usuario no tiene permitido usar esta linea de la API.');
};
const isObjectEmpty = (obj) => {
for (let key in obj) {
if (obj.hasOwnProperty(key)) return false;
@@ -156,5 +162,6 @@ module.exports = {
validarFecha,
validarNumero,
validarPreTermino,
validarAccesibilidad,
isObjectEmpty,
};
+20 -13
View File
@@ -22,6 +22,7 @@ const rechazarTermino = require('../controller/Servicio/rechazarTermino');
const rechazarInforme = require('../controller/Servicio/rechazarInforme');
const update = require('../controller/Servicio/update');
const reporte = require('../controller/Servicio/reporte');
const gustavoBazPrada = require('../controller/Servicio/gustavoBazPrada');
const eliminarArchivo = (filename) => {
fs.unlinkSync(`./server/uploads/${filename}`);
@@ -83,19 +84,25 @@ app.get(`${route}/alumno`, verificaToken, (req, res) => {
});
});
app.get(
`${route}/reporte`,
// verificaToken,
(req, res) => {
return reporte(req.query)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
}
);
app.get(`${route}/reporte`, verificaToken, (req, res) => {
return reporte(req.query)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
app.get(`${route}/gustavo_bas_prada`, verificaToken, (req, res) => {
return gustavoBazPrada(req.query)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
app.put(`${route}/cancelar`, verificaToken, (req, res) => {
return cancelar(req.body)