|
| 1 | +import { |
| 2 | + Body, |
| 3 | + Controller, |
| 4 | + Delete, |
| 5 | + Get, |
| 6 | + Param, |
| 7 | + Post, |
| 8 | + Put, |
| 9 | + Query, |
| 10 | +} from '@nestjs/common'; |
| 11 | +import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request'; |
| 12 | +import { Organization } from '@prisma/client'; |
| 13 | +import { ApiTags } from '@nestjs/swagger'; |
| 14 | +import { CheckPolicies } from '@gitroom/backend/services/auth/permissions/permissions.ability'; |
| 15 | +import { |
| 16 | + AuthorizationActions, |
| 17 | + Sections, |
| 18 | +} from '@gitroom/backend/services/auth/permissions/permissions.service'; |
| 19 | +import { AutopostService } from '@gitroom/nestjs-libraries/database/prisma/autopost/autopost.service'; |
| 20 | +import { AutopostDto } from '@gitroom/nestjs-libraries/dtos/autopost/autopost.dto'; |
| 21 | +import { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser'; |
| 22 | +import dayjs from 'dayjs'; |
| 23 | + |
| 24 | +@ApiTags('Autopost') |
| 25 | +@Controller('/autopost') |
| 26 | +export class AutopostController { |
| 27 | + constructor(private _autopostsService: AutopostService) {} |
| 28 | + |
| 29 | + @Get('/') |
| 30 | + async getAutoposts(@GetOrgFromRequest() org: Organization) { |
| 31 | + return this._autopostsService.getAutoposts(org.id); |
| 32 | + } |
| 33 | + |
| 34 | + @Post('/') |
| 35 | + @CheckPolicies([AuthorizationActions.Create, Sections.WEBHOOKS]) |
| 36 | + async createAutopost( |
| 37 | + @GetOrgFromRequest() org: Organization, |
| 38 | + @Body() body: AutopostDto |
| 39 | + ) { |
| 40 | + return this._autopostsService.createAutopost(org.id, body); |
| 41 | + } |
| 42 | + |
| 43 | + @Put('/:id') |
| 44 | + async updateAutopost( |
| 45 | + @GetOrgFromRequest() org: Organization, |
| 46 | + @Body() body: AutopostDto, |
| 47 | + @Param('id') id: string |
| 48 | + ) { |
| 49 | + return this._autopostsService.createAutopost(org.id, body, id); |
| 50 | + } |
| 51 | + |
| 52 | + @Delete('/:id') |
| 53 | + async deleteAutopost( |
| 54 | + @GetOrgFromRequest() org: Organization, |
| 55 | + @Param('id') id: string |
| 56 | + ) { |
| 57 | + return this._autopostsService.deleteAutopost(org.id, id); |
| 58 | + } |
| 59 | + |
| 60 | + @Post('/:id/active') |
| 61 | + async changeActive( |
| 62 | + @GetOrgFromRequest() org: Organization, |
| 63 | + @Param('id') id: string, |
| 64 | + @Body('active') active: boolean |
| 65 | + ) { |
| 66 | + return this._autopostsService.changeActive(org.id, id, active); |
| 67 | + } |
| 68 | + |
| 69 | + @Post('/send') |
| 70 | + async sendWebhook(@Query('url') url: string) { |
| 71 | + return this._autopostsService.loadXML(url); |
| 72 | + } |
| 73 | +} |
0 commit comments