El excel ya no se guarda en el servidor
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
PORT=5089
|
||||
|
||||
# DB_HOST=132.248.180.82
|
||||
# DB_USER=user_cedetec
|
||||
# DB_PASSWORD=c3t3d3c
|
||||
# DB_NAME=Betelgeuse_Cedetec_Prueba
|
||||
# DB_PORT=
|
||||
DB_HOST=132.248.180.82
|
||||
DB_USER=user_cedetec
|
||||
DB_PASSWORD=c3t3d3c
|
||||
DB_NAME=Betelgeuse_Cedetec_Prueba
|
||||
DB_PORT=
|
||||
|
||||
DB_HOST=localhost
|
||||
DB_USER=root
|
||||
DB_PASSWORD=Dosmiluno2001
|
||||
DB_NAME=cedetec_proyectos
|
||||
DB_PORT=3306
|
||||
# DB_HOST=localhost
|
||||
# DB_USER=root
|
||||
# DB_PASSWORD=Dosmiluno2001
|
||||
# DB_NAME=cedetec_proyectos
|
||||
# DB_PORT=3306
|
||||
|
||||
DB_HOST_DSC = 132.248.180.82
|
||||
DB_USER_DSC = sites_user
|
||||
|
||||
@@ -50,8 +50,7 @@ export class EventosController {
|
||||
|
||||
@Get(':id/exportExcel')
|
||||
async exportarExcel (@Param('id', ParseIntPipe)id:number ,@Res() res: Response){
|
||||
const filePath = await this.eventoService.exportarParticipantes(id);
|
||||
res.download(filePath);
|
||||
this.eventoService.exportarParticipantes(id, res)
|
||||
}
|
||||
|
||||
@Post('disponibles')
|
||||
|
||||
@@ -7,6 +7,7 @@ import { actualizarEventoDto } from './dto/actualizarEvento.dto';
|
||||
import { crearEventoDto } from './dto/crearEvento.dto';
|
||||
import { Evento } from './evento.entity';
|
||||
import * as ExcelJS from 'exceljs';
|
||||
import { Response } from 'express';
|
||||
|
||||
@Injectable()
|
||||
export class EventosService {
|
||||
@@ -95,27 +96,57 @@ export class EventosService {
|
||||
return participantes;
|
||||
}
|
||||
|
||||
async exportarParticipantes(idEvento: number): Promise<string> {
|
||||
async exportarParticipantes(idEvento: number, res: Response): Promise<void> {
|
||||
const participantes: Participante[] = await this.getParticipantes(idEvento);
|
||||
/* console.log(participantes);
|
||||
*/
|
||||
/*console.log(participantes);*/
|
||||
|
||||
// Crear el workbook y la worksheet
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const worksheet = workbook.addWorksheet('Participantes');
|
||||
|
||||
// Definir las columnas
|
||||
worksheet.columns = [
|
||||
{ header: 'Asistencia', key: 'asistencia', width: 10, style: {alignment: {horizontal: 'center'}}},
|
||||
{ header: 'Nombre', key: 'nombre', width: 20, style: {alignment: {horizontal: 'center'}} },
|
||||
{ header: 'Apellido Paterno', key: 'apellido_paterno', width: 20, style: {alignment: {horizontal: 'center'}} },
|
||||
{ header: 'Apellido Materno', key: 'apellido_materno', width: 20, style: {alignment: {horizontal: 'center'}} },
|
||||
{ header: 'Carrera', key: 'carrera', width: 20, style: {alignment: {horizontal: 'center'}} },
|
||||
{ header: 'Email', key: 'email', width: 35, style: {alignment: {horizontal: 'center'}} },
|
||||
{
|
||||
header: 'Asistencia',
|
||||
key: 'asistencia',
|
||||
width: 10,
|
||||
style: { alignment: { horizontal: 'center' } },
|
||||
},
|
||||
{
|
||||
header: 'Nombre',
|
||||
key: 'nombre',
|
||||
width: 20,
|
||||
style: { alignment: { horizontal: 'center' } },
|
||||
},
|
||||
{
|
||||
header: 'Apellido Paterno',
|
||||
key: 'apellido_paterno',
|
||||
width: 20,
|
||||
style: { alignment: { horizontal: 'center' } },
|
||||
},
|
||||
{
|
||||
header: 'Apellido Materno',
|
||||
key: 'apellido_materno',
|
||||
width: 20,
|
||||
style: { alignment: { horizontal: 'center' } },
|
||||
},
|
||||
{
|
||||
header: 'Carrera',
|
||||
key: 'carrera',
|
||||
width: 20,
|
||||
style: { alignment: { horizontal: 'center' } },
|
||||
},
|
||||
{
|
||||
header: 'Email',
|
||||
key: 'email',
|
||||
width: 35,
|
||||
style: { alignment: { horizontal: 'center' } },
|
||||
},
|
||||
{
|
||||
header: 'Institución Procedencia',
|
||||
key: 'institucion_procedencia',
|
||||
width: 30,
|
||||
style: {alignment: {horizontal: 'center'}}
|
||||
style: { alignment: { horizontal: 'center' } },
|
||||
},
|
||||
];
|
||||
// Agregar los datos a la worksheet
|
||||
@@ -135,19 +166,24 @@ export class EventosService {
|
||||
|
||||
// Generar el archivo Excel y guardarlo en el servidor
|
||||
const fileName = `participantes-${idEvento}.xlsx`;
|
||||
const filePath = `./${fileName}`;
|
||||
/* await workbook.xlsx.writeFile(filePath);
|
||||
*/
|
||||
// Devolver la ruta del archivo para que el cliente pueda descargarlo
|
||||
return filePath;
|
||||
// Configurar la respuesta HTTP para descargar el archivo
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
);
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
|
||||
|
||||
// Escribir el archivo Excel en la respuesta HTTP
|
||||
const buffer = await workbook.xlsx.writeBuffer();
|
||||
res.send(buffer);
|
||||
}
|
||||
|
||||
getEventosDisponibles(){
|
||||
getEventosDisponibles() {
|
||||
const hoy = new Date();
|
||||
return this.eventoRepository.find({
|
||||
where: {
|
||||
fecha_fin: MoreThanOrEqual(hoy)
|
||||
}
|
||||
})
|
||||
fecha_fin: MoreThanOrEqual(hoy),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user