Enable comment deletion on CommentDrawer (#460)

* Enable comment deletion on people and companies page

* Add storybook test
This commit is contained in:
Charles Bochet
2023-06-27 09:00:14 -07:00
committed by GitHub
parent c9038bb93a
commit a6b2fd75ba
12 changed files with 199 additions and 37 deletions

View File

@ -78,6 +78,7 @@ export class AbilityFactory {
can(AbilityAction.Read, 'CommentThread', { workspaceId: workspace.id });
can(AbilityAction.Create, 'CommentThread');
can(AbilityAction.Update, 'CommentThread', { workspaceId: workspace.id });
can(AbilityAction.Delete, 'CommentThread', { workspaceId: workspace.id });
// Comment
can(AbilityAction.Read, 'Comment', { workspaceId: workspace.id });

View File

@ -18,12 +18,15 @@ import { AbilityGuard } from 'src/guards/ability.guard';
import { CheckAbilities } from 'src/decorators/check-abilities.decorator';
import {
CreateCommentThreadAbilityHandler,
DeleteCommentThreadAbilityHandler,
ReadCommentThreadAbilityHandler,
UpdateCommentThreadAbilityHandler,
} from 'src/ability/handlers/comment-thread.ability-handler';
import { UserAbility } from 'src/decorators/user-ability.decorator';
import { AppAbility } from 'src/ability/ability.factory';
import { accessibleBy } from '@casl/prisma';
import { AffectedRows } from 'src/core/@generated/prisma/affected-rows.output';
import { DeleteManyCommentThreadArgs } from 'src/core/@generated/comment-thread/delete-many-comment-thread.args';
@UseGuards(JwtAuthGuard)
@Resolver(() => CommentThread)
@ -99,4 +102,17 @@ export class CommentThreadResolver {
return result;
}
@Mutation(() => AffectedRows, {
nullable: false,
})
@UseGuards(AbilityGuard)
@CheckAbilities(DeleteCommentThreadAbilityHandler)
async deleteManyCommentThreads(
@Args() args: DeleteManyCommentThreadArgs,
): Promise<AffectedRows> {
return this.commentThreadService.deleteMany({
...args,
});
}
}

View File

@ -0,0 +1,5 @@
-- DropForeignKey
ALTER TABLE "comments" DROP CONSTRAINT "comments_commentThreadId_fkey";
-- AddForeignKey
ALTER TABLE "comments" ADD CONSTRAINT "comments_commentThreadId_fkey" FOREIGN KEY ("commentThreadId") REFERENCES "comment_threads"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,5 @@
-- DropForeignKey
ALTER TABLE "comment_thread_targets" DROP CONSTRAINT "comment_thread_targets_commentThreadId_fkey";
-- AddForeignKey
ALTER TABLE "comment_thread_targets" ADD CONSTRAINT "comment_thread_targets_commentThreadId_fkey" FOREIGN KEY ("commentThreadId") REFERENCES "comment_threads"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -255,7 +255,7 @@ model Comment {
authorId String
author User @relation(fields: [authorId], references: [id])
commentThreadId String
commentThread CommentThread @relation(fields: [commentThreadId], references: [id])
commentThread CommentThread @relation(fields: [commentThreadId], references: [id], onDelete: Cascade)
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
/// @TypeGraphQL.omit(input: true, output: true)
@ -275,7 +275,7 @@ model CommentThreadTarget {
updatedAt DateTime @updatedAt
deletedAt DateTime?
commentThreadId String
commentThread CommentThread @relation(fields: [commentThreadId], references: [id])
commentThread CommentThread @relation(fields: [commentThreadId], references: [id], onDelete: Cascade)
commentableType CommentableType
commentableId String