feat: add TipoEvento entity and related functionality
- Introduced TipoEvento entity with enum for event types. - Created DTOs for creating and updating TipoEvento. - Implemented TipoEvento service with methods for CRUD operations and seeding initial data. - Added TipoEvento controller for handling HTTP requests related to event types. - Integrated TipoEvento into the main application module. - Updated Evento entity to include a relationship with TipoEvento. - Enhanced ParticipanteEvento service to register attendance using QR tokens. - Implemented QR token generation and validation for event attendance. - Updated API documentation for new endpoints and functionalities. - Adjusted TypeOrm configuration to include new entities.
This commit is contained in:
+58
-4
@@ -10,14 +10,20 @@ import {
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { QrService } from './qr.service';
|
||||
import { QrTokenService } from './qr-token.service';
|
||||
import { Qr } from './qr.entity';
|
||||
import { CreateQrDto } from './dto/create-qr.dto';
|
||||
import { UpdateQrDto } from './dto/update.qr.dto';
|
||||
import { ApiOperation, ApiParam, ApiQuery } from '@nestjs/swagger';
|
||||
import { ValidateQrTokenDto } from './dto/validate-qr-token.dto';
|
||||
import { ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('QR')
|
||||
@Controller('qr')
|
||||
export class QrController {
|
||||
constructor(private qrService: QrService) {}
|
||||
constructor(
|
||||
private qrService: QrService,
|
||||
private qrTokenService: QrTokenService,
|
||||
) {}
|
||||
|
||||
@Get('generate')
|
||||
@ApiOperation({ summary: 'Genera un código QR a partir de un texto' })
|
||||
@@ -31,16 +37,64 @@ export class QrController {
|
||||
}
|
||||
|
||||
@Get('asistencia/:idParticipante/:idEvento')
|
||||
@ApiOperation({ summary: 'Genera un código QR para asistencia con IDs de participante y evento' })
|
||||
@ApiOperation({
|
||||
summary:
|
||||
'Genera un código QR para asistencia con IDs de participante y evento',
|
||||
})
|
||||
@ApiParam({ name: 'idParticipante', description: 'ID del participante' })
|
||||
@ApiParam({ name: 'idEvento', description: 'ID del evento' })
|
||||
async generateAsistenciaQR(
|
||||
@Param('idParticipante', ParseIntPipe) idParticipante: number,
|
||||
@Param('idEvento', ParseIntPipe) idEvento: number
|
||||
@Param('idEvento', ParseIntPipe) idEvento: number,
|
||||
): Promise<string> {
|
||||
return this.qrService.generateAsistenciaQR(idParticipante, idEvento);
|
||||
}
|
||||
|
||||
@Post('validate-token')
|
||||
@ApiOperation({ summary: 'Valida un token de QR para asistencia' })
|
||||
async validateQrToken(@Body() validateDto: ValidateQrTokenDto) {
|
||||
const tokenData = this.qrTokenService.validateQrToken(validateDto.token);
|
||||
|
||||
if (!tokenData) {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'Token inválido o expirado',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
data: tokenData,
|
||||
message: 'Token válido',
|
||||
};
|
||||
}
|
||||
|
||||
@Get('generate-token/:idParticipante/:idEvento/:idCuestionario')
|
||||
@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' })
|
||||
async generateQrToken(
|
||||
@Param('idParticipante', ParseIntPipe) idParticipante: number,
|
||||
@Param('idEvento', ParseIntPipe) idEvento: number,
|
||||
@Param('idCuestionario', ParseIntPipe) idCuestionario: number,
|
||||
) {
|
||||
const token = this.qrTokenService.generateQrToken(
|
||||
idParticipante,
|
||||
idEvento,
|
||||
idCuestionario,
|
||||
);
|
||||
|
||||
return {
|
||||
token,
|
||||
qr_data: {
|
||||
id_participante: idParticipante,
|
||||
id_evento: idEvento,
|
||||
id_cuestionario: idCuestionario,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@Get()
|
||||
getQrs(): Promise<Qr[]> {
|
||||
return this.qrService.getQrs();
|
||||
|
||||
Reference in New Issue
Block a user