Skip to content

Commit

Permalink
fix(nestjs): 切换到 nest 服务后,部分文章的评论无法查询到
Browse files Browse the repository at this point in the history
fix #202
  • Loading branch information
cumt-robin committed Feb 21, 2025
1 parent ece9776 commit 9dcc2a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-ants-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nest-server": patch
---

切换到 nest 服务后,部分文章的评论无法查询到
36 changes: 20 additions & 16 deletions app/nest-server/src/modules/comment/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ export class CommentService {

async getPage(query: GetCommentPageDto) {
const { id, pageNo, pageSize } = query;
const [data, total] = await this.commentRepository.findAndCount({
where: {
article_id: id ? id : IsNull(),
approved: 1,
replies: {
approved: 1,
},
},
skip: (pageNo - 1) * pageSize,
take: pageSize,
relations: ["replies"],
select: ["id", "article_id", "content", "create_time", "nick_name", "site_url", "avatar", "device"],
order: {
create_time: "DESC",
},
});
const queryBuilder = this.commentRepository
.createQueryBuilder("comment")
.select([
"comment.id",
"comment.article_id",
"comment.content",
"comment.create_time",
"comment.nick_name",
"comment.site_url",
"comment.avatar",
"comment.device",
])
.leftJoinAndSelect("comment.replies", "reply", "reply.approved = :replyApproved", { replyApproved: 1 })
.where("comment.approved = :approved", { approved: 1 })
.andWhere("comment.article_id = :articleId", { articleId: id ? id : IsNull() })
.skip((pageNo - 1) * pageSize)
.take(pageSize)
.orderBy("comment.create_time", "DESC");

const [data, total] = await queryBuilder.getManyAndCount();

return {
data,
Expand Down
1 change: 0 additions & 1 deletion app/nest-server/src/modules/reply/reply.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export class ReplyService {
// 发个邮件通知下
const jumpUrl = jump_url || this.configService.get("SITE_URL");
await this.emailService.sendMail({
from: `"${this.configService.get("BLOG_NAME")}" <${this.configService.get("AUTHOR_EMAIL")}>`,
to: email,
subject: `${this.configService.get("BLOG_NAME")}《回复审核通过》`,
html: `<h1 style="text-align:center;color:#409EFF">感谢您在<a href="${jumpUrl}">${this.configService.get("BLOG_NAME")}</a>留下足迹</h1>\
Expand Down

0 comments on commit 9dcc2a2

Please sign in to comment.