This commit is contained in:
evenegas
2025-10-01 12:11:44 -06:00
parent f346da673b
commit 0745ddc8b4
3 changed files with 14 additions and 13 deletions
@@ -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);
+6 -10
View File
@@ -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<string> {
fecha_fin: Date,
): string {
const payload = {
id_participante,
id_evento,
@@ -46,16 +47,11 @@ export class QrTokenService {
this.configService.get<string>('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,
+4 -1
View File
@@ -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 {