From 3db1076ee64a8eb43d9328ea170a31b2f2ed52bf Mon Sep 17 00:00:00 2001 From: santiago Date: Fri, 3 Oct 2025 14:29:14 -0600 Subject: [PATCH] Modificaciones --- src/cuestionario/cuestionario.service.ts | 2 +- src/qr/qr-token.service.ts | 60 +++++++++++++----------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/cuestionario/cuestionario.service.ts b/src/cuestionario/cuestionario.service.ts index 295743d..74f1fdf 100644 --- a/src/cuestionario/cuestionario.service.ts +++ b/src/cuestionario/cuestionario.service.ts @@ -148,7 +148,7 @@ export class CuestionarioService { console.log("Fecha de inicio: ", fecha_inicio); const fecha_fin = new Date(qRow.getCell(6).value as string); - console.log("Fecha de fin: ", fecha_fin); + console.log("Fecha de fin: ", fecha_fin); const id_tipo_evento= Number(qRow.getCell(8).value); const plantillaId = PLANTILLA_MAP[plantilla]; const base = PLANTILLAS.find(p => p.id === plantillaId); diff --git a/src/qr/qr-token.service.ts b/src/qr/qr-token.service.ts index 105d6a4..45c9360 100644 --- a/src/qr/qr-token.service.ts +++ b/src/qr/qr-token.service.ts @@ -51,9 +51,11 @@ export class QrTokenService { // Convert fecha_fin to seconds from now for expiresIn const expiresInSeconds = Math.floor((fecha_fin.getTime() - Date.now()) / 1000); + console.log("Caducidad token: ", Math.floor((fecha_fin.getTime() - Date.now()) / 1000)); + return this.jwtService.sign(payload, { secret, - expiresIn: expiresInSeconds > 0 ? expiresInSeconds : 0, // El QR puede ser válido por 30 días + expiresIn: expiresInSeconds > 0 ? expiresInSeconds : 3600, // El QR puede ser válido por 30 días }); } @@ -70,6 +72,7 @@ export class QrTokenService { type: string; iat: number; } | null >{ + try { const secret = this.configService.get('QR_JWT_SECRET') || @@ -79,37 +82,40 @@ export class QrTokenService { const decoded = this.jwtService.verify(token, { secret }); + //console.log("fecha fin:", fecha_fin2.fecha_fin); + console.log("este es el token", decoded); + const fecha_fin2 = await this.eventoREpo.findOne({ - where: { id_evento:decoded.id_evento }, + where: { id_evento:decoded.id_evento }, - }); + }); - - - - if (!fecha_fin2) { - throw new UnauthorizedException('Evento no encontrado'); - } - const fechaFinEvento = new Date(fecha_fin2.fecha_fin); // UTC - const now = new Date(); - console.log(fechaFinEvento.getTime()) - console.log(now.getTime) - if (fechaFinEvento.getTime() < now.getTime()) { - throw new Error('El evento ha finalizado'); - } - - // Verificar que sea un token de tipo QR de asistencia - if (decoded.type !== 'qr_asistencia') { - return null; + if (!fecha_fin2) { + throw new UnauthorizedException('Evento no encontrado'); + } + const fechaFinEvento = new Date(fecha_fin2.fecha_fin); // UTC + const now = new Date(); + console.log("Fecha fin cruda (de DB):", fecha_fin2.fecha_fin); + console.log("Fecha fin convertida:", fechaFinEvento.toISOString()); + console.log("Fecha fin timestamp:", fechaFinEvento.getTime()); + console.log("Fecha actual:", now.toISOString()); + console.log("Fecha actual timestamp:", now.getTime()); + if (fechaFinEvento.getTime() < now.getTime()) { + throw new Error('El evento ha finalizado'); } - return { - id_participante: decoded.id_participante, - id_evento: decoded.id_evento, - id_cuestionario: decoded.id_cuestionario, - type: decoded.type, - iat: decoded.iat, - }; + // Verificar que sea un token de tipo QR de asistencia + if (decoded.type !== 'qr_asistencia') { + return null; + } + + return { + id_participante: decoded.id_participante, + id_evento: decoded.id_evento, + id_cuestionario: decoded.id_cuestionario, + type: decoded.type, + iat: decoded.iat, + }; } catch (error) { console.error('Error validando token QR:', error.message); return null;