Endpoint del reporte, falta validar cosas
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
Generated
+22
@@ -13,6 +13,8 @@
|
||||
"bcrypt": "^5.0.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"colors": "^1.4.0",
|
||||
"convert-array-to-csv": "^2.0.0",
|
||||
"convert-csv-to-json": "^1.3.3",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
@@ -616,6 +618,16 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/convert-array-to-csv": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/convert-array-to-csv/-/convert-array-to-csv-2.0.0.tgz",
|
||||
"integrity": "sha512-dxUINCt28k6WbXGMoB+AaKjGY0Y6GkKwZmT+kvD4nJgVCOKsnIQ3G6n0v2II1lG4NwXQk6EWZ+pPDub9wcqqMg=="
|
||||
},
|
||||
"node_modules/convert-csv-to-json": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/convert-csv-to-json/-/convert-csv-to-json-1.3.3.tgz",
|
||||
"integrity": "sha512-lIQrCmEw0GCywtVWeJ/AGv5hhSTPsMFdqOf9GcMtActqO2Gt8z1RZgfw9NBOll479cIPM6BqDOFC8R3W7bSwtA=="
|
||||
},
|
||||
"node_modules/cookie": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz",
|
||||
@@ -3196,6 +3208,16 @@
|
||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
||||
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
|
||||
},
|
||||
"convert-array-to-csv": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/convert-array-to-csv/-/convert-array-to-csv-2.0.0.tgz",
|
||||
"integrity": "sha512-dxUINCt28k6WbXGMoB+AaKjGY0Y6GkKwZmT+kvD4nJgVCOKsnIQ3G6n0v2II1lG4NwXQk6EWZ+pPDub9wcqqMg=="
|
||||
},
|
||||
"convert-csv-to-json": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/convert-csv-to-json/-/convert-csv-to-json-1.3.3.tgz",
|
||||
"integrity": "sha512-lIQrCmEw0GCywtVWeJ/AGv5hhSTPsMFdqOf9GcMtActqO2Gt8z1RZgfw9NBOll479cIPM6BqDOFC8R3W7bSwtA=="
|
||||
},
|
||||
"cookie": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz",
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
"bcrypt": "^5.0.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"colors": "^1.4.0",
|
||||
"convert-array-to-csv": "^2.0.0",
|
||||
"convert-csv-to-json": "^1.3.3",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
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;
|
||||
@@ -28,7 +28,7 @@ const validarTicket = async (body) => {
|
||||
message: '¡ El ticket a sido validado de forma correcta !',
|
||||
}))
|
||||
.catch((err) => {
|
||||
throw new Error('No fue posible validar el ticekt. ' + err);
|
||||
throw new Error('No fue posible validar el ticket. ' + err);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ const controllerPath = '../controller/Admin';
|
||||
const todasInscripciones = require(`${controllerPath}/todasInscripciones`);
|
||||
const ticket = require(`${controllerPath}/ticket`);
|
||||
const validarTicket = require(`${controllerPath}/validarTicket`);
|
||||
const reporte = require(`${controllerPath}/reporte`);
|
||||
|
||||
app.get(`${route}/todas_inscripciones`, (req, res) => {
|
||||
return todasInscripciones(req.query)
|
||||
@@ -40,4 +41,14 @@ app.put(`${route}/validar`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/reporte`, (req, res) => {
|
||||
return reporte(req.query)
|
||||
.then((data) => {
|
||||
res.download(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
idInscripcion,validacion,confirmacion,folio,monto,fechaInscripcion,idArea
|
||||
1,false,false,7410,12,Thu Feb 03 2022 22:45:50 GMT-0600 (hora estándar central),1
|
||||
2,true,false,9630,85,Thu Feb 03 2022 22:55:00 GMT-0600 (hora estándar central),3
|
||||
3,true,false,8520,89,Fri Feb 04 2022 22:51:02 GMT-0600 (hora estándar central),1
|
||||
4,"",false,9654,89,Fri Feb 04 2022 23:19:48 GMT-0600 (hora estándar central),3
|
||||
|
Reference in New Issue
Block a user