feat: delete channel

This commit is contained in:
Nevo David 2024-07-12 11:44:13 +07:00
parent c3e6333a5b
commit 02ffca06c4
3 changed files with 16 additions and 12 deletions

View File

@ -31,7 +31,7 @@ import { NotEnoughScopesFilter } from '@gitroom/nestjs-libraries/integrations/in
export class IntegrationsController {
constructor(
private _integrationManager: IntegrationManager,
private _integrationService: IntegrationService
private _integrationService: IntegrationService,
) {}
@Get('/')
getIntegration() {
@ -293,7 +293,6 @@ export class IntegrationsController {
@GetOrgFromRequest() org: Organization,
@Body('id') id: string
) {
// @ts-ignore
return this._integrationService.deleteChannel(org.id, id);
}
}

View File

@ -187,8 +187,9 @@ export class IntegrationRepository {
});
}
countPostsForChannel(org: string, id: string) {
return this._posts.model.post.count({
getPostsForChannel(org: string, id: string) {
return this._posts.model.post.groupBy({
by: ['group'],
where: {
organizationId: org,
integrationId: id,

View File

@ -7,13 +7,15 @@ 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 _notificationService: NotificationService,
private _postsService: PostsService
) {}
createOrUpdateIntegration(
org: string,
@ -143,15 +145,14 @@ export class IntegrationService {
}
async deleteChannel(org: string, id: string) {
const isTherePosts = await this._integrationRepository.countPostsForChannel(
const isTherePosts = await this._integrationRepository.getPostsForChannel(
org,
id
);
if (isTherePosts) {
throw new HttpException(
'There are posts for this channel',
HttpStatus.NOT_ACCEPTABLE
);
if (isTherePosts.length) {
for (const post of isTherePosts) {
await this._postsService.deletePost(org, post.group);
}
}
return this._integrationRepository.deleteChannel(org, id);
@ -217,7 +218,10 @@ export class IntegrationService {
page
);
await this.checkForDeletedOnceAndUpdate(org, String(getIntegrationInformation.id));
await this.checkForDeletedOnceAndUpdate(
org,
String(getIntegrationInformation.id)
);
await this._integrationRepository.updateIntegration(String(id), {
picture: getIntegrationInformation.picture,