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 { export class IntegrationsController {
constructor( constructor(
private _integrationManager: IntegrationManager, private _integrationManager: IntegrationManager,
private _integrationService: IntegrationService private _integrationService: IntegrationService,
) {} ) {}
@Get('/') @Get('/')
getIntegration() { getIntegration() {
@ -293,7 +293,6 @@ export class IntegrationsController {
@GetOrgFromRequest() org: Organization, @GetOrgFromRequest() org: Organization,
@Body('id') id: string @Body('id') id: string
) { ) {
// @ts-ignore
return this._integrationService.deleteChannel(org.id, id); return this._integrationService.deleteChannel(org.id, id);
} }
} }

View File

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

View File

@ -7,13 +7,15 @@ import { SocialProvider } from '@gitroom/nestjs-libraries/integrations/social/so
import { Integration } from '@prisma/client'; import { Integration } from '@prisma/client';
import { NotificationService } from '@gitroom/nestjs-libraries/database/prisma/notifications/notification.service'; import { NotificationService } from '@gitroom/nestjs-libraries/database/prisma/notifications/notification.service';
import { LinkedinPageProvider } from '@gitroom/nestjs-libraries/integrations/social/linkedin.page.provider'; import { LinkedinPageProvider } from '@gitroom/nestjs-libraries/integrations/social/linkedin.page.provider';
import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service';
@Injectable() @Injectable()
export class IntegrationService { export class IntegrationService {
constructor( constructor(
private _integrationRepository: IntegrationRepository, private _integrationRepository: IntegrationRepository,
private _integrationManager: IntegrationManager, private _integrationManager: IntegrationManager,
private _notificationService: NotificationService private _notificationService: NotificationService,
private _postsService: PostsService
) {} ) {}
createOrUpdateIntegration( createOrUpdateIntegration(
org: string, org: string,
@ -143,15 +145,14 @@ export class IntegrationService {
} }
async deleteChannel(org: string, id: string) { async deleteChannel(org: string, id: string) {
const isTherePosts = await this._integrationRepository.countPostsForChannel( const isTherePosts = await this._integrationRepository.getPostsForChannel(
org, org,
id id
); );
if (isTherePosts) { if (isTherePosts.length) {
throw new HttpException( for (const post of isTherePosts) {
'There are posts for this channel', await this._postsService.deletePost(org, post.group);
HttpStatus.NOT_ACCEPTABLE }
);
} }
return this._integrationRepository.deleteChannel(org, id); return this._integrationRepository.deleteChannel(org, id);
@ -217,7 +218,10 @@ export class IntegrationService {
page page
); );
await this.checkForDeletedOnceAndUpdate(org, String(getIntegrationInformation.id)); await this.checkForDeletedOnceAndUpdate(
org,
String(getIntegrationInformation.id)
);
await this._integrationRepository.updateIntegration(String(id), { await this._integrationRepository.updateIntegration(String(id), {
picture: getIntegrationInformation.picture, picture: getIntegrationInformation.picture,