Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: delete posts

Nevo Davidbed6f25db87d
diff --git a/apps/backend/src/api/routes/integrations.controller.ts b/apps/backend/src/api/routes/integrations.controller.ts
index d3058a992..a633bb4d9 100644
--- a/apps/backend/src/api/routes/integrations.controller.ts
+++ b/apps/backend/src/api/routes/integrations.controller.ts
@@ -25,6 +25,7 @@ import { pricing } from '@gitroom/nestjs-libraries/database/prisma/subscriptions
import { ApiTags } from '@nestjs/swagger';
import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request';
import { NotEnoughScopesFilter } from '@gitroom/nestjs-libraries/integrations/integration.missing.scopes';
+import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service';
@ApiTags('Integrations')
@Controller('/integrations')
@@ -32,6 +33,7 @@ export class IntegrationsController {
constructor(
private _integrationManager: IntegrationManager,
private _integrationService: IntegrationService,
+ private _postService: PostsService
) {}
@Get('/')
getIntegration() {
@@ -289,10 +291,20 @@ export class IntegrationsController {
}
@Delete('/')
- deleteChannel(
+ async deleteChannel(
@GetOrgFromRequest() org: Organization,
@Body('id') id: string
) {
+ const isTherePosts = await this._integrationService.getPostsForChannel(
+ org.id,
+ id
+ );
+ if (isTherePosts.length) {
+ for (const post of isTherePosts) {
+ await this._postService.deletePost(org.id, post.group);
+ }
+ }
+
return this._integrationService.deleteChannel(org.id, id);
}
}
diff --git a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts
index f21c09cee..aca087ef8 100644
--- a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts
@@ -7,15 +7,13 @@ import { SocialProvider } from '@gitroom/nestjs-libraries/integrations/social/so
import { Integration } from '@prisma/client';
import { NotificationService } from '@gitroom/nestjs-libraries/database/prisma/notifications/notification.service';
import { LinkedinPageProvider } from '@gitroom/nestjs-libraries/integrations/social/linkedin.page.provider';
-import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service';
@Injectable()
export class IntegrationService {
constructor(
private _integrationRepository: IntegrationRepository,
private _integrationManager: IntegrationManager,
- private _notificationService: NotificationService,
- private _postsService: PostsService
+ private _notificationService: NotificationService
) {}
createOrUpdateIntegration(
org: string,
@@ -144,17 +142,11 @@ export class IntegrationService {
return this._integrationRepository.enableChannel(org, id);
}
- async deleteChannel(org: string, id: string) {
- const isTherePosts = await this._integrationRepository.getPostsForChannel(
- org,
- id
- );
- if (isTherePosts.length) {
- for (const post of isTherePosts) {
- await this._postsService.deletePost(org, post.group);
- }
- }
+ async getPostsForChannel(org: string, id: string) {
+ return this._integrationRepository.getPostsForChannel(org, id);
+ }
+ async deleteChannel(org: string, id: string) {
return this._integrationRepository.deleteChannel(org, id);
}