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()
author: User;
@ManyToOne(() => BlogCategory, (category) => category.blogs, { nullable: false })
@ManyToOne(() => BlogCategory, (category) => category.blogs, { nullable: false, onDelete: "CASCADE" })
@Index()
category: BlogCategory;
+1 -1
View File
@@ -59,7 +59,7 @@ export class BlogsService {
const category = await this.blogCategoriesRepository.findOneBy({ id });
if (!category) throw new BadRequestException(BlogMessage.CATEGORY_NOT_FOUND);
await this.blogCategoriesRepository.softDelete({ id });
await this.blogCategoriesRepository.delete({ id });
return {
message: CommonMessage.DELETED,
};
@@ -41,6 +41,7 @@ export class BlogCommentsRepository extends Repository<BlogComment> {
const { limit, skip } = PaginationUtils(queryDto);
const query = this.createQueryBuilder("blogComment")
.leftJoin("blogComment.blog", "blog")
.where("blog.deletedAt IS NULL")
.addSelect(["blog.id", "blog.title"])
.leftJoin("blogComment.user", "user")
.addSelect(["user.id", "user.firstName", "user.lastName"]);