ticket.controller.ts64 lines, 1.6 KB
| 1 | import { |
| 2 | Controller, |
| 3 | Get, |
| 4 | Post, |
| 5 | Body, |
| 6 | Param, |
| 7 | Request, |
| 8 | UseGuards, |
| 9 | ParseUUIDPipe, |
| 10 | } from '@nestjs/common'; |
| 11 | import { AuthGuard } from '@nestjs/passport'; |
| 12 | import { TicketService } from './ticket.service'; |
| 13 | import { PurchaseTicketDto, CheckInTicketDto } from '@app/common'; |
| 14 | |
| 15 | @Controller('tickets') |
| 16 | @UseGuards(AuthGuard('jwt')) |
| 17 | export class TicketController { |
| 18 | constructor(private readonly ticketsService: TicketService) {} |
| 19 | |
| 20 | @Post('purchase') |
| 21 | purchase( |
| 22 | @Body() purchaseDto: PurchaseTicketDto, |
| 23 | @Request() req: { user: { userId: string } }, |
| 24 | ) { |
| 25 | return this.ticketsService.purchase(purchaseDto, req.user.userId); |
| 26 | } |
| 27 | |
| 28 | @Get('my-tickets') |
| 29 | findMyTickets(@Request() req: { user: { userId: string } }) { |
| 30 | return this.ticketsService.findMyTickets(req.user.userId); |
| 31 | } |
| 32 | |
| 33 | @Get(':id') |
| 34 | findOne( |
| 35 | @Param('id', ParseUUIDPipe) id: string, |
| 36 | @Request() req: { user: { userId: string } }, |
| 37 | ) { |
| 38 | return this.ticketsService.findOne(id, req.user.userId); |
| 39 | } |
| 40 | |
| 41 | @Post(':id/cancel') |
| 42 | cancel( |
| 43 | @Param('id', ParseUUIDPipe) id: string, |
| 44 | @Request() req: { user: { userId: string } }, |
| 45 | ) { |
| 46 | return this.ticketsService.cancel(id, req.user.userId); |
| 47 | } |
| 48 | |
| 49 | @Post('check-in') |
| 50 | checkIn( |
| 51 | @Body() checkInDto: CheckInTicketDto, |
| 52 | @Request() req: { user: { userId: string } }, |
| 53 | ) { |
| 54 | return this.ticketsService.checkIn(checkInDto, req.user.userId); |
| 55 | } |
| 56 | |
| 57 | @Get('event/:eventId') |
| 58 | findEventTickets( |
| 59 | @Param('eventId', ParseUUIDPipe) eventId: string, |
| 60 | @Request() req: { user: { userId: string } }, |
| 61 | ) { |
| 62 | return this.ticketsService.findEventTickets(eventId, req.user.userId); |
| 63 | } |
| 64 | } |