CSV para llenar la base del at
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
const moment = require('moment');
|
||||
const { convertArrayToCSV } = require('convert-array-to-csv');
|
||||
const { Op } = require('sequelize');
|
||||
const { Op, where } = 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 Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const reporte = async (body) => {
|
||||
const inicio = validar.validarFecha(body.inicio, 'fecha de inicio', false);
|
||||
@@ -20,23 +21,35 @@ const reporte = async (body) => {
|
||||
{ fechaInscripcion: { [Op.lte]: fin.format() } },
|
||||
],
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Usuario,
|
||||
attributes: ['numeroCuenta'],
|
||||
},
|
||||
],
|
||||
})
|
||||
.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: moment(res[i].fechaInscripcion).format('L'),
|
||||
idArea: res[i].idArea,
|
||||
});
|
||||
if (body.tipo) {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
data.push({
|
||||
numeroCuenta: res[i].Usuario.numeroCuenta,
|
||||
idArea: res[i].idArea,
|
||||
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
data.push({
|
||||
numeroCuenta: res[i].Usuario.numeroCuenta,
|
||||
validacion: res[i].validacion,
|
||||
confirmacion: res[i].confirmacion,
|
||||
folio: res[i].folio,
|
||||
monto: res[i].monto,
|
||||
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
|
||||
idArea: res[i].idArea,
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log(data);
|
||||
await helper.eliminarArchivo(path).catch((err) => {});
|
||||
return helper.crearArchivo(path, convertArrayToCSV(data));
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
idInscripcion,validacion,confirmacion,folio,monto,fechaInscripcion,idArea
|
||||
1,1,false,8520,65,Wed Feb 16 2022 10:37:15 GMT-0600 (hora estándar central),1
|
||||
2,2,false,9630,65,Wed Feb 16 2022 10:48:43 GMT-0600 (hora estándar central),3
|
||||
3,2,false,8563,7,Wed Feb 16 2022 17:30:47 GMT-0600 (hora estándar central),1
|
||||
numeroCuenta,idArea,fechaInscripcion
|
||||
419085500,1,02/16/2022
|
||||
419085500,3,02/16/2022
|
||||
316304326,1,02/16/2022
|
||||
|
||||
|
Reference in New Issue
Block a user