后端修复获取评论失败的bug
This commit is contained in:
@@ -77,7 +77,7 @@ export class BlogController {
|
||||
throw new BadRequestException('文章不存在或未公开');
|
||||
}
|
||||
|
||||
return await this.blogService.getComments(id);
|
||||
return await this.blogService.getComments(blog);
|
||||
}
|
||||
|
||||
// 该接口允许匿名评论,但仍需验证userId合法性
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user