chore: add comment reply for review and blog comment

This commit is contained in:
mahyargdz
2025-08-31 09:55:33 +03:30
parent 9c409bef27
commit 8e9b939a0b
20 changed files with 624 additions and 222 deletions
@@ -0,0 +1,31 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { BlogCommentReply } from "../entities/blog-comment-reply.entity";
@Injectable()
export class BlogCommentReplyRepository extends Repository<BlogCommentReply> {
constructor(@InjectRepository(BlogCommentReply) repository: Repository<BlogCommentReply>) {
super(repository.target, repository.manager, repository.queryRunner);
}
//+********************
async findByCommentId(commentId: string): Promise<BlogCommentReply[]> {
return this.createQueryBuilder("reply")
.leftJoinAndSelect("reply.author", "author")
.leftJoinAndSelect("reply.parentReply", "parentReply")
.leftJoinAndSelect("reply.replies", "replies")
.where("reply.comment.id = :commentId", { commentId })
.andWhere("reply.parentReply IS NULL")
.orderBy("reply.createdAt", "ASC")
.getMany();
}
//+********************
async findRepliesByParentId(parentId: string): Promise<BlogCommentReply[]> {
return this.createQueryBuilder("reply")
.leftJoinAndSelect("reply.author", "author")
.where("reply.parentReply.id = :parentId", { parentId })
.orderBy("reply.createdAt", "ASC")
.getMany();
}
}
@@ -25,6 +25,7 @@ export class BlogCommentsRepository extends Repository<BlogComment> {
order: { createdAt: "DESC" },
relations: {
user: true,
replies: true,
},
select: {
id: true,
@@ -33,6 +34,7 @@ export class BlogCommentsRepository extends Repository<BlogComment> {
createdAt: true,
status: true,
user: { id: true, firstName: true, lastName: true },
replies: { id: true, content: true, createdAt: true, author: { id: true, firstName: true, lastName: true } },
},
});
}
@@ -44,7 +46,11 @@ export class BlogCommentsRepository extends Repository<BlogComment> {
.where("blog.deletedAt IS NULL")
.addSelect(["blog.id", "blog.title"])
.leftJoin("blogComment.user", "user")
.addSelect(["user.id", "user.firstName", "user.lastName"]);
.addSelect(["user.id", "user.firstName", "user.lastName"])
.leftJoin("blogComment.replies", "replies")
.addSelect(["replies.id", "replies.content", "replies.createdAt"])
.leftJoin("replies.author", "repliesAuthor")
.addSelect(["repliesAuthor.id", "repliesAuthor.firstName", "repliesAuthor.lastName"]);
if (queryDto.q) {
query.andWhere("blogComment.content ILIKE :q", { q: `%${queryDto.q}%` });
@@ -58,13 +64,14 @@ export class BlogCommentsRepository extends Repository<BlogComment> {
return query.getManyAndCount();
}
//*********************************** */
async findBlogCommentsByBlogId(blogId: string) {
return this.find({
where: { blog: { id: blogId, deletedAt: IsNull() }, status: CommentStatus.APPROVED },
order: { createdAt: "DESC" },
relations: {
user: true,
replies: true,
},
select: {
id: true,
@@ -73,6 +80,7 @@ export class BlogCommentsRepository extends Repository<BlogComment> {
createdAt: true,
status: true,
user: { id: true, firstName: true, lastName: true, profilePic: true },
replies: { id: true, content: true, createdAt: true, author: { id: true, firstName: true, lastName: true } },
},
});
}