Spaces:
Runtime error
Runtime error
| import { Controller, Get, Post, Put, Delete, Param, Body, HttpCode, HttpStatus } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger'; | |
| import { WebhookService } from './webhook.service'; | |
| import { CreateWebhookDto, UpdateWebhookDto, WebhookResponseDto } from './dto'; | |
| import { RequireRole } from '../auth/decorators/auth.decorators'; | |
| import { ApiKeyRole } from '../auth/entities/api-key.entity'; | |
| ('webhooks') | |
| ('sessions/:sessionId/webhooks') | |
| export class WebhookController { | |
| constructor(private readonly webhookService: WebhookService) {} | |
| () | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'Create a webhook for the session' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ | |
| status: 201, | |
| description: 'Webhook created', | |
| type: WebhookResponseDto, | |
| }) | |
| async create(('sessionId') sessionId: string, () dto: CreateWebhookDto): Promise<WebhookResponseDto> { | |
| return WebhookResponseDto.fromEntity(await this.webhookService.create(sessionId, dto)); | |
| } | |
| () | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'List all webhooks for a session' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ | |
| status: 200, | |
| description: 'List of webhooks', | |
| type: [WebhookResponseDto], | |
| }) | |
| async findBySession(('sessionId') sessionId: string): Promise<WebhookResponseDto[]> { | |
| return WebhookResponseDto.fromEntities(await this.webhookService.findBySession(sessionId)); | |
| } | |
| (':id') | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'Get a webhook by ID' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'id', description: 'Webhook ID' }) | |
| ({ | |
| status: 200, | |
| description: 'Webhook details', | |
| type: WebhookResponseDto, | |
| }) | |
| ({ status: 404, description: 'Webhook not found' }) | |
| async findOne(('sessionId') sessionId: string, ('id') id: string): Promise<WebhookResponseDto> { | |
| return WebhookResponseDto.fromEntity(await this.webhookService.findOne(sessionId, id)); | |
| } | |
| (':id') | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'Update a webhook' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'id', description: 'Webhook ID' }) | |
| ({ | |
| status: 200, | |
| description: 'Webhook updated', | |
| type: WebhookResponseDto, | |
| }) | |
| ({ status: 404, description: 'Webhook not found' }) | |
| async update( | |
| ('sessionId') sessionId: string, | |
| ('id') id: string, | |
| () dto: UpdateWebhookDto, | |
| ): Promise<WebhookResponseDto> { | |
| return WebhookResponseDto.fromEntity(await this.webhookService.update(sessionId, id, dto)); | |
| } | |
| (':id/test') | |
| (ApiKeyRole.OPERATOR) | |
| (HttpStatus.OK) | |
| ({ summary: 'Test a webhook by sending a test payload' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'id', description: 'Webhook ID' }) | |
| ({ status: 200, description: 'Test result' }) | |
| ({ status: 404, description: 'Webhook not found' }) | |
| async test( | |
| ('sessionId') sessionId: string, | |
| ('id') id: string, | |
| ): Promise<{ success: boolean; statusCode?: number; error?: string }> { | |
| return this.webhookService.test(sessionId, id); | |
| } | |
| (':id') | |
| (ApiKeyRole.OPERATOR) | |
| (HttpStatus.NO_CONTENT) | |
| ({ summary: 'Delete a webhook' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'id', description: 'Webhook ID' }) | |
| ({ status: 204, description: 'Webhook deleted' }) | |
| ({ status: 404, description: 'Webhook not found' }) | |
| async delete(('sessionId') sessionId: string, ('id') id: string): Promise<void> { | |
| return this.webhookService.delete(sessionId, id); | |
| } | |
| } | |