Skip to content

Commit ac4c990

Browse files
authored
Merge pull request #614 from gitroomhq/feat/auto-post
Add auto-posting from RSS
2 parents b4a8a13 + 4a787cc commit ac4c990

File tree

19 files changed

+2366
-5778
lines changed

19 files changed

+2366
-5778
lines changed

apps/backend/src/api/api.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { ShortLinkService } from '@gitroom/nestjs-libraries/short-linking/short.
3030
import { Nowpayments } from '@gitroom/nestjs-libraries/crypto/nowpayments';
3131
import { WebhookController } from '@gitroom/backend/api/routes/webhooks.controller';
3232
import { SignatureController } from '@gitroom/backend/api/routes/signature.controller';
33+
import { AutopostController } from '@gitroom/backend/api/routes/autopost.controller';
3334

3435
const authenticatedController = [
3536
UsersController,
@@ -46,6 +47,7 @@ const authenticatedController = [
4647
AgenciesController,
4748
WebhookController,
4849
SignatureController,
50+
AutopostController,
4951
];
5052
@Module({
5153
imports: [UploadModule],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
}

apps/backend/src/api/routes/public.controller.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ export class PublicController {
132132
}
133133

134134
@Post('/crypto/:path')
135-
async cryptoPost(
136-
@Body() body: any,
137-
@Param('path') path: string
138-
) {
135+
async cryptoPost(@Body() body: any, @Param('path') path: string) {
139136
console.log('cryptoPost', body, path);
140137
return this._nowpayments.processPayment(path, body);
141138
}

0 commit comments

Comments
 (0)