src/webhooks/webhook.controller.ts
webhooks
Methods |
| Async create | |||||||||
create(orgId: string, dto: CreateWebhookDto)
|
|||||||||
Decorators :
@Post()
|
|||||||||
|
Defined in src/webhooks/webhook.controller.ts:37
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async delete |
delete(id: string, orgId: string)
|
Decorators :
@Delete(':id')
|
|
Defined in src/webhooks/webhook.controller.ts:70
|
|
Returns :
unknown
|
| Async list | ||||||
list(orgId: string)
|
||||||
Decorators :
@Get()
|
||||||
|
Defined in src/webhooks/webhook.controller.ts:62
|
||||||
|
Parameters :
Returns :
unknown
|
| Async test |
test(id: string, orgId: string)
|
Decorators :
@Post(':id/test')
|
|
Defined in src/webhooks/webhook.controller.ts:84
|
|
Returns :
unknown
|
import {
Controller,
Post,
Get,
Delete,
Body,
Param,
UseGuards,
HttpCode,
HttpStatus,
} from '@nestjs/common';
import {
ApiTags,
ApiBearerAuth,
ApiOperation,
ApiResponse,
} from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { CurrentUser } from '../auth/decorators/current-user.decorator';
import { WebhookService } from './webhook.service';
import { CreateWebhookDto } from './dto/create-webhook.dto';
@ApiTags('Webhooks')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('webhooks')
export class WebhookController {
constructor(private readonly webhookService: WebhookService) {}
@Post()
@ApiOperation({
summary: 'Create a webhook subscription',
description:
'Subscribes to events. The signing secret is returned in the response (save it to verify payloads).',
})
@ApiResponse({ status: 201, description: 'Webhook created.' })
async create(
@CurrentUser('organizationId') orgId: string,
@Body() dto: CreateWebhookDto,
) {
const webhook = await this.webhookService.createWebhook(
orgId,
dto.url,
dto.events,
dto.secret,
);
return {
message:
'Webhook created. Save the signing secret to verify incoming payloads.',
id: webhook.id,
url: webhook.url,
events: webhook.events,
secret: webhook.secret,
};
}
@Get()
@ApiOperation({
summary: 'List all webhooks',
description: 'Returns all webhook subscriptions for the organization.',
})
async list(@CurrentUser('organizationId') orgId: string) {
return this.webhookService.listWebhooks(orgId);
}
@Delete(':id')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Delete a webhook' })
@ApiResponse({ status: 200, description: 'Webhook deleted.' })
async delete(
@Param('id') id: string,
@CurrentUser('organizationId') orgId: string,
) {
await this.webhookService.deleteWebhook(id, orgId);
return { message: 'Webhook deleted successfully' };
}
@Post(':id/test')
@HttpCode(HttpStatus.OK)
@ApiOperation({
summary: 'Send a test ping to a webhook',
description: 'Sends a webhook.test event to verify connectivity.',
})
async test(
@Param('id') id: string,
@CurrentUser('organizationId') orgId: string,
) {
return this.webhookService.testWebhook(id, orgId);
}
}