Modificaciones

This commit is contained in:
santiago
2025-10-03 14:29:14 -06:00
parent 0837bdd17b
commit 3db1076ee6
2 changed files with 34 additions and 28 deletions
+1 -1
View File
@@ -148,7 +148,7 @@ export class CuestionarioService {
console.log("Fecha de inicio: ", fecha_inicio); console.log("Fecha de inicio: ", fecha_inicio);
const fecha_fin = new Date(qRow.getCell(6).value as string); 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 id_tipo_evento= Number(qRow.getCell(8).value);
const plantillaId = PLANTILLA_MAP[plantilla]; const plantillaId = PLANTILLA_MAP[plantilla];
const base = PLANTILLAS.find(p => p.id === plantillaId); const base = PLANTILLAS.find(p => p.id === plantillaId);
+33 -27
View File
@@ -51,9 +51,11 @@ export class QrTokenService {
// Convert fecha_fin to seconds from now for expiresIn // Convert fecha_fin to seconds from now for expiresIn
const expiresInSeconds = Math.floor((fecha_fin.getTime() - Date.now()) / 1000); 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, { return this.jwtService.sign(payload, {
secret, 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; type: string;
iat: number; iat: number;
} | null >{ } | null >{
try { try {
const secret = const secret =
this.configService.get<string>('QR_JWT_SECRET') || this.configService.get<string>('QR_JWT_SECRET') ||
@@ -79,37 +82,40 @@ export class QrTokenService {
const decoded = this.jwtService.verify(token, { secret }); 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({ 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');
}
if (!fecha_fin2) { const fechaFinEvento = new Date(fecha_fin2.fecha_fin); // UTC
throw new UnauthorizedException('Evento no encontrado'); const now = new Date();
} console.log("Fecha fin cruda (de DB):", fecha_fin2.fecha_fin);
const fechaFinEvento = new Date(fecha_fin2.fecha_fin); // UTC console.log("Fecha fin convertida:", fechaFinEvento.toISOString());
const now = new Date(); console.log("Fecha fin timestamp:", fechaFinEvento.getTime());
console.log(fechaFinEvento.getTime()) console.log("Fecha actual:", now.toISOString());
console.log(now.getTime) console.log("Fecha actual timestamp:", now.getTime());
if (fechaFinEvento.getTime() < now.getTime()) { if (fechaFinEvento.getTime() < now.getTime()) {
throw new Error('El evento ha finalizado'); 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 { // Verificar que sea un token de tipo QR de asistencia
id_participante: decoded.id_participante, if (decoded.type !== 'qr_asistencia') {
id_evento: decoded.id_evento, return null;
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) { } catch (error) {
console.error('Error validando token QR:', error.message); console.error('Error validando token QR:', error.message);
return null; return null;