Download apps/backend/src/api/routes/webhooks.controller.ts from Leon4gr45/postio: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/Leon4gr45/postio/resolve/main/apps/backend/src/api/routes/webhooks.controller.ts
- Command line
-
hf download hf://spaces/Leon4gr45/postio/apps/backend/src/api/routes/webhooks.controller.ts
-
curl -L -o webhooks.controller.ts https://huggingface.co/spaces/Leon4gr45/postio/resolve/main/apps/backend/src/api/routes/webhooks.controller.ts
1.93 kB
| import { | |
| Body, | |
| Controller, | |
| Delete, | |
| Get, | |
| Param, | |
| Post, | |
| Put, | |
| Query, | |
| } from '@nestjs/common'; | |
| import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request'; | |
| import { Organization } from '@prisma/client'; | |
| import { ApiTags } from '@nestjs/swagger'; | |
| import { WebhooksService } from '@gitroom/nestjs-libraries/database/prisma/webhooks/webhooks.service'; | |
| import { CheckPolicies } from '@gitroom/backend/services/auth/permissions/permissions.ability'; | |
| import { | |
| OnlyURL, UpdateDto, WebhooksDto | |
| } from '@gitroom/nestjs-libraries/dtos/webhooks/webhooks.dto'; | |
| import { AuthorizationActions, Sections } from '@gitroom/backend/services/auth/permissions/permission.exception.class'; | |
| ('Webhooks') | |
| ('/webhooks') | |
| export class WebhookController { | |
| constructor(private _webhooksService: WebhooksService) {} | |
| ('/') | |
| async getStatistics(() org: Organization) { | |
| return this._webhooksService.getWebhooks(org.id); | |
| } | |
| ('/') | |
| ([AuthorizationActions.Create, Sections.WEBHOOKS]) | |
| async createAWebhook( | |
| () org: Organization, | |
| () body: WebhooksDto | |
| ) { | |
| return this._webhooksService.createWebhook(org.id, body); | |
| } | |
| ('/') | |
| async updateWebhook( | |
| () org: Organization, | |
| () body: UpdateDto | |
| ) { | |
| return this._webhooksService.createWebhook(org.id, body); | |
| } | |
| ('/:id') | |
| async deleteWebhook( | |
| () org: Organization, | |
| ('id') id: string | |
| ) { | |
| return this._webhooksService.deleteWebhook(org.id, id); | |
| } | |
| ('/send') | |
| async sendWebhook(() body: any, () query: OnlyURL) { | |
| try { | |
| await fetch(query.url, { | |
| method: 'POST', | |
| body: JSON.stringify(body), | |
| headers: { 'Content-Type': 'application/json' }, | |
| }); | |
| } catch (err) { | |
| /** sent **/ | |
| } | |
| return { send: true }; | |
| } | |
| } | |