This commit is contained in:
santiago
2025-10-03 14:29:55 -06:00
2 changed files with 24 additions and 26 deletions
@@ -268,10 +268,7 @@ export class ParticipanteEventoService {
const tokenData = this.qrTokenService.validateQrToken(qrToken);
if (!tokenData) {
throw new HttpException(
'Token QR inválido o expirado',
HttpStatus.BAD_REQUEST,
);
return null;
}
return tokenData
+23 -22
View File
@@ -50,7 +50,7 @@ export class QrTokenService {
console.log("fecha de caducidad:",fecha_fin);
// Convert fecha_fin to seconds from now for expiresIn
const expiresInSeconds = Math.floor((fecha_fin.getTime() - Date.now()) / 1000);
console.log("expiresInSeconds:",expiresInSeconds);
console.log("Caducidad token: ", Math.floor((fecha_fin.getTime() - Date.now()) / 1000));
return this.jwtService.sign(payload, {
@@ -71,6 +71,7 @@ export class QrTokenService {
id_cuestionario: number;
type: string;
iat: number;
exp?: number;
} | null >{
try {
@@ -88,34 +89,34 @@ export class QrTokenService {
const fecha_fin2 = await this.eventoREpo.findOne({
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("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');
}
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;
}
return {
id_participante: decoded.id_participante,
id_evento: decoded.id_evento,
id_cuestionario: decoded.id_cuestionario,
type: decoded.type,
iat: decoded.iat,
};
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;