From 0745ddc8b4030eac256e99021fa100ea4f51882f Mon Sep 17 00:00:00 2001 From: evenegas Date: Wed, 1 Oct 2025 12:11:44 -0600 Subject: [PATCH] qr --- .../cuestionario_respondido.service.ts | 6 ++++-- src/qr/qr-token.service.ts | 16 ++++++---------- src/qr/qr.controller.ts | 5 ++++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/cuestionario_respondido/cuestionario_respondido.service.ts b/src/cuestionario_respondido/cuestionario_respondido.service.ts index 0f8d78a..47c120a 100644 --- a/src/cuestionario_respondido/cuestionario_respondido.service.ts +++ b/src/cuestionario_respondido/cuestionario_respondido.service.ts @@ -112,10 +112,11 @@ export class CuestionarioRespondidoService { if (cuestionario && cuestionario.evento) { try { // Generar token para el QR - qrToken = await this.qrTokenService.generateQrToken( + qrToken = this.qrTokenService.generateQrToken( participante.id_participante, cuestionario.evento.id_evento, cuestionario.id_cuestionario, + cuestionario.fecha_fin ); // Generar código QR con el token @@ -336,10 +337,11 @@ export class CuestionarioRespondidoService { } // Generar token para el QR - qrToken = await this.qrTokenService.generateQrToken( + qrToken = this.qrTokenService.generateQrToken( participante.id_participante, cuestionario.evento.id_evento, cuestionario.id_cuestionario, + cuestionario.fecha_fin ); qrBuffer = await QRCode.toBuffer(qrToken); diff --git a/src/qr/qr-token.service.ts b/src/qr/qr-token.service.ts index 5e8b934..ae13a9d 100644 --- a/src/qr/qr-token.service.ts +++ b/src/qr/qr-token.service.ts @@ -27,11 +27,12 @@ export class QrTokenService { * @param id_cuestionario ID del cuestionario * @returns Token JWT codificado */ - async generateQrToken( + generateQrToken( id_participante: number, id_evento: number, id_cuestionario: number, - ): Promise { + fecha_fin: Date, + ): string { const payload = { id_participante, id_evento, @@ -46,16 +47,11 @@ export class QrTokenService { this.configService.get('JWT_SECRET', 'tu_clave_secreta'); - const fecha_fin2 = await this.eventoREpo.findOne({ - where: { id_evento }, + - }); - - if (!fecha_fin2) { - throw new UnauthorizedException('Cuestionario no encontrado'); - } + // Convert fecha_fin to seconds from now for expiresIn - const expiresInSeconds = Math.floor((fecha_fin2?.fecha_fin.getTime() - Date.now()) / 1000); + const expiresInSeconds = Math.floor((fecha_fin.getTime() - Date.now()) / 1000); return this.jwtService.sign(payload, { secret, diff --git a/src/qr/qr.controller.ts b/src/qr/qr.controller.ts index b435d5f..f64f9c8 100644 --- a/src/qr/qr.controller.ts +++ b/src/qr/qr.controller.ts @@ -69,20 +69,23 @@ export class QrController { }; } - @Get('generate-token/:idParticipante/:idEvento/:idCuestionario') + @Get('generate-token/:idParticipante/:idEvento/:idCuestionario/:fechaFin') @ApiOperation({ summary: 'Genera un token JWT para QR de asistencia' }) @ApiParam({ name: 'idParticipante', description: 'ID del participante' }) @ApiParam({ name: 'idEvento', description: 'ID del evento' }) @ApiParam({ name: 'idCuestionario', description: 'ID del cuestionario' }) + @ApiParam({ name: 'fechaFin', description: 'Fecha de fin de validez del token (ISO 8601)' }) async generateQrToken( @Param('idParticipante', ParseIntPipe) idParticipante: number, @Param('idEvento', ParseIntPipe) idEvento: number, @Param('idCuestionario', ParseIntPipe) idCuestionario: number, + @Param('fechaFin') fechaFin: Date, ) { const token = await this.qrTokenService.generateQrToken( idParticipante, idEvento, idCuestionario, + fechaFin ); return {