reportes y correcion de termino
This commit is contained in:
@@ -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;
|
||||
@@ -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) => ({
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user