feat: delete posts

This commit is contained in:
Nevo David 2024-07-12 11:54:50 +07:00
parent 02ffca06c4
commit bed6f25db8
2 changed files with 18 additions and 14 deletions

View File

@ -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);
}
}

View File

@ -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);
}