All files / src/features/events events.controller.ts

50% Statements 5/10
100% Branches 0/0
50% Functions 5/10
50% Lines 5/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                  10x           1x         1x             1x         1x                                                                            
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'
import { EventsService } from './events.service'
import { CreateEventDto, UpdateEventDto } from '@fundraising/types'
import { AuthGuard } from '@nestjs/passport'
import { RolesGuard } from '../auth/guards/roles.guard'
import { Roles } from '../auth/decorators/roles.decorator'
 
@Controller('events')
export class EventsController {
    constructor(private readonly eventsService: EventsService) {}
 
    @Post()
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN')
    create(@Body() createEventDto: CreateEventDto) {
        return this.eventsService.create(createEventDto)
    }
 
    @Get('public')
    findPublic() {
        return this.eventsService.findPublic()
    }
 
    @Get()
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN', 'STAFF')
    findAll() {
        return this.eventsService.findAll()
    }
 
    @Get(':slug')
    findOne(@Param('slug') slug: string) {
        return this.eventsService.findOne(slug)
    }
 
    @Patch(':id')
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN')
    update(@Param('id') id: string, @Body() updateEventDto: UpdateEventDto) {
        return this.eventsService.update(id, updateEventDto)
    }
 
    @Delete(':id')
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN')
    remove(@Param('id') id: string) {
        return this.eventsService.remove(id)
    }
 
    @Get(':id/staff')
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN', 'STAFF') // Staff should check their own assignment? Or just Admin? Let's say Admin/Staff.
    findStaff(@Param('id') id: string) {
        return this.eventsService.findStaff(id)
    }
 
    @Post(':id/staff/:staffId')
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN')
    assignStaff(@Param('id') id: string, @Param('staffId') staffId: string) {
        return this.eventsService.assignStaff(id, staffId)
    }
 
    @Delete(':id/staff/:staffId')
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN')
    unassignStaff(@Param('id') id: string, @Param('staffId') staffId: string) {
        return this.eventsService.unassignStaff(id, staffId)
    }
}