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);
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);
+33 -27
View File
@@ -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<string>('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;