后端修复获取评论失败的bug

This commit is contained in:
2025-06-23 09:15:10 +08:00
parent 5fdd69acb8
commit b75765a6d8
2 changed files with 4 additions and 9 deletions

View File

@@ -77,7 +77,7 @@ export class BlogController {
throw new BadRequestException('文章不存在或未公开');
}
return await this.blogService.getComments(id);
return await this.blogService.getComments(blog);
}
// 该接口允许匿名评论但仍需验证userId合法性

View File

@@ -95,14 +95,9 @@ export class BlogService {
await this.blogRepository.increment({ id }, 'viewCount', 1);
}
async getComments(blogId: string) {
const blog = await this.findById(blogId);
if (!blog) {
throw new Error('文章不存在');
}
async getComments(blog: Blog) {
return this.blogCommentRepository.find({
where: { blog },
where: { blog: { id: blog.id } },
relations: ['user'],
order: {
createdAt: 'DESC',