bc5ddb29c7
- 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.
123 lines
3.4 KiB
TypeScript
123 lines
3.4 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
ParseIntPipe,
|
|
Patch,
|
|
Post,
|
|
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 { 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,
|
|
private qrTokenService: QrTokenService,
|
|
) {}
|
|
|
|
@Get('generate')
|
|
@ApiOperation({ summary: 'Genera un código QR a partir de un texto' })
|
|
@ApiQuery({
|
|
name: 'text',
|
|
required: true,
|
|
description: 'Texto a codificar en el QR',
|
|
})
|
|
async generateQRCode(@Query('text') text: string): Promise<string> {
|
|
return this.qrService.generateQRCode(text);
|
|
}
|
|
|
|
@Get('asistencia/:idParticipante/:idEvento')
|
|
@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,
|
|
): 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();
|
|
}
|
|
|
|
@Get(':id')
|
|
getQr(@Param('id', ParseIntPipe) id: number) {
|
|
return this.qrService.getQr(id);
|
|
}
|
|
|
|
@Post() //en el body ValidationPipe
|
|
createQr(@Body() newQr: CreateQrDto) {
|
|
return this.qrService.createQr(newQr);
|
|
}
|
|
|
|
@Delete(':id')
|
|
deleteQr(@Param('id', ParseIntPipe) id: number) {
|
|
return this.qrService.deleteQr(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
updateQr(@Param('id', ParseIntPipe) id: number, @Body() qr: UpdateQrDto) {
|
|
return this.qrService.updateQr(id, qr);
|
|
}
|
|
}
|