import { Body, Controller, Delete, Get, HttpCode, Param, Patch, Post, } from '@nestjs/common'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { RequirePermission } from '../auth/decorators/require-permission.decorator'; import { CurrentUser } from '../auth/decorators/current-user.decorator'; import type { AuthenticatedUser } from '../auth/types/authenticated-user'; import { CreateWebhookDto } from './dto/create-webhook.dto'; import { UpdateWebhookDto } from './dto/update-webhook.dto'; import { WebhooksService } from './webhooks.service'; @ApiTags('webhooks') @ApiBearerAuth() @Controller('webhooks') export class WebhooksController { constructor(private readonly webhooksService: WebhooksService) {} @RequirePermission('webhooks:read') @Get() findAll() { return this.webhooksService.findAll(); } @RequirePermission('webhooks:create') @Post() create( @Body() dto: CreateWebhookDto, @CurrentUser() actor: AuthenticatedUser, ) { return this.webhooksService.create(dto, actor.id); } @RequirePermission('webhooks:update') @Patch(':id') update( @Param('id') id: string, @Body() dto: UpdateWebhookDto, @CurrentUser() actor: AuthenticatedUser, ) { return this.webhooksService.update(id, dto, actor.id); } @RequirePermission('webhooks:delete') @Delete(':id') @HttpCode(204) delete(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) { return this.webhooksService.delete(id, actor.id); } }