All files / src/features/white-labeling white-labeling.controller.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 6/6
100% Lines 9/9

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                                    14x       1x             1x         2x 2x 1x   1x             1x             1x      
import {
    Controller,
    Get,
    Param,
    NotFoundException,
    Patch,
    Body,
    UseGuards,
    Delete,
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { RolesGuard } from '../auth/guards/roles.guard'
import { Roles } from '../auth/decorators/roles.decorator'
import { WhiteLabelingService } from './white-labeling.service'
import { EventConfig } from '@fundraising/white-labeling'
 
@Controller()
export class WhiteLabelingController {
    constructor(private readonly service: WhiteLabelingService) {}
 
    @Get('settings/global')
    async getGlobalSettings() {
        return this.service.getGlobalSettings()
    }
 
    @Patch('settings/global')
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN')
    async updateGlobalSettings(@Body() config: Partial<EventConfig>) {
        return this.service.updateGlobalSettings(config)
    }
 
    @Get('events/:slug/settings')
    async getEventSettings(@Param('slug') slug: string) {
        const settings = await this.service.getEventSettings(slug)
        if (!settings) {
            throw new NotFoundException(`Event settings for '${slug}' not found`)
        }
        return settings
    }
 
    @Patch('events/:id/branding')
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN')
    async updateEventSettings(@Param('id') eventId: string, @Body() config: Partial<EventConfig>) {
        return this.service.updateEventSettings(eventId, config)
    }
 
    @Delete('events/:id/branding')
    @UseGuards(AuthGuard('jwt'), RolesGuard)
    @Roles('ADMIN')
    async resetEventSettings(@Param('id') eventId: string) {
        return this.service.resetEventSettings(eventId)
    }
}