47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
const moment = require('moment');
|
|
const { convertArrayToCSV } = require('convert-array-to-csv');
|
|
const { Op } = require('sequelize');
|
|
const helperPath = '../../helper';
|
|
const helper = require(`${helperPath}/helper`);
|
|
const validar = require(`${helperPath}/validar`);
|
|
const dbPath = '../../db/tablas';
|
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
|
|
|
const reporte = async (body) => {
|
|
const inicio = validar.validarFecha(body.inicio, 'fecha de inicio', false);
|
|
const fin = validar.validarFecha(body.fin, 'fecha fin', false);
|
|
const path = `server/uploads/reporte.csv`;
|
|
const data = [];
|
|
|
|
return Inscripcion.findAll({
|
|
where: {
|
|
[Op.and]: [
|
|
{ fechaInscripcion: { [Op.gte]: inicio.format() } },
|
|
{ fechaInscripcion: { [Op.lte]: fin.format() } },
|
|
],
|
|
},
|
|
})
|
|
.then(async (res) => {
|
|
console.log(res);
|
|
|
|
for (let i = 0; i < res.length; i++) {
|
|
console.log(res[i].idInscripcion);
|
|
data.push({
|
|
idInscripcion: res[i].idInscripcion,
|
|
validacion: res[i].validacion,
|
|
confirmacion: res[i].confirmacion,
|
|
folio: res[i].folio,
|
|
monto: res[i].monto,
|
|
fechaInscripcion: res[i].fechaInscripcion,
|
|
idArea: res[i].idArea,
|
|
});
|
|
}
|
|
console.log(data);
|
|
await helper.eliminarArchivo(path).catch((err) => {});
|
|
return helper.crearArchivo(path, convertArrayToCSV(data));
|
|
})
|
|
.then((res) => path);
|
|
};
|
|
|
|
module.exports = reporte;
|