postiz-app/apps/backend/src/api/routes/autopost.controller.ts
Nevo David be5d871896
Some checks failed
Build Containers / build-containers-common (push) Has been cancelled
Build / build (22.12.0) (push) Has been cancelled
Build Containers / build-containers (amd64, ubuntu-latest) (push) Has been cancelled
Build Containers / build-containers (arm64, ubuntu-24.04-arm) (push) Has been cancelled
Build Containers / build-container-manifest (push) Has been cancelled
fix: autopost url
2026-03-25 17:45:18 +07:00

69 lines
2 KiB
TypeScript

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 { CheckPolicies } from '@gitroom/backend/services/auth/permissions/permissions.ability';
import { AutopostService } from '@gitroom/nestjs-libraries/database/prisma/autopost/autopost.service';
import { AutopostDto } from '@gitroom/nestjs-libraries/dtos/autopost/autopost.dto';
import { AuthorizationActions, Sections } from '@gitroom/backend/services/auth/permissions/permission.exception.class';
import { OnlyURL } from '@gitroom/nestjs-libraries/dtos/webhooks/webhooks.dto';
@ApiTags('Autopost')
@Controller('/autopost')
export class AutopostController {
constructor(private _autopostsService: AutopostService) {}
@Get('/')
async getAutoposts(@GetOrgFromRequest() org: Organization) {
return this._autopostsService.getAutoposts(org.id);
}
@Post('/')
@CheckPolicies([AuthorizationActions.Create, Sections.WEBHOOKS])
async createAutopost(
@GetOrgFromRequest() org: Organization,
@Body() body: AutopostDto
) {
return this._autopostsService.createAutopost(org.id, body);
}
@Put('/:id')
async updateAutopost(
@GetOrgFromRequest() org: Organization,
@Body() body: AutopostDto,
@Param('id') id: string
) {
return this._autopostsService.createAutopost(org.id, body, id);
}
@Delete('/:id')
async deleteAutopost(
@GetOrgFromRequest() org: Organization,
@Param('id') id: string
) {
return this._autopostsService.deleteAutopost(org.id, id);
}
@Post('/:id/active')
async changeActive(
@GetOrgFromRequest() org: Organization,
@Param('id') id: string,
@Body('active') active: boolean
) {
return this._autopostsService.changeActive(org.id, id, active);
}
@Post('/send')
async sendWebhook(@Query() query: OnlyURL) {
return this._autopostsService.loadXML(query.url);
}
}