fix: the blog entitiy cascade option

This commit is contained in:
mahyargdz
2025-04-22 16:45:11 +03:30
parent 53b4a396ba
commit 385181b30f
3 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ export class Blog extends BaseEntity {
@Index() @Index()
author: User; author: User;
@ManyToOne(() => BlogCategory, (category) => category.blogs, { nullable: false }) @ManyToOne(() => BlogCategory, (category) => category.blogs, { nullable: false, onDelete: "CASCADE" })
@Index() @Index()
category: BlogCategory; category: BlogCategory;
+1 -1
View File
@@ -59,7 +59,7 @@ export class BlogsService {
const category = await this.blogCategoriesRepository.findOneBy({ id }); const category = await this.blogCategoriesRepository.findOneBy({ id });
if (!category) throw new BadRequestException(BlogMessage.CATEGORY_NOT_FOUND); if (!category) throw new BadRequestException(BlogMessage.CATEGORY_NOT_FOUND);
await this.blogCategoriesRepository.softDelete({ id }); await this.blogCategoriesRepository.delete({ id });
return { return {
message: CommonMessage.DELETED, message: CommonMessage.DELETED,
}; };
@@ -41,6 +41,7 @@ export class BlogCommentsRepository extends Repository<BlogComment> {
const { limit, skip } = PaginationUtils(queryDto); const { limit, skip } = PaginationUtils(queryDto);
const query = this.createQueryBuilder("blogComment") const query = this.createQueryBuilder("blogComment")
.leftJoin("blogComment.blog", "blog") .leftJoin("blogComment.blog", "blog")
.where("blog.deletedAt IS NULL")
.addSelect(["blog.id", "blog.title"]) .addSelect(["blog.id", "blog.title"])
.leftJoin("blogComment.user", "user") .leftJoin("blogComment.user", "user")
.addSelect(["user.id", "user.firstName", "user.lastName"]); .addSelect(["user.id", "user.firstName", "user.lastName"]);