后端修复获取评论失败的bug
This commit is contained in:
@@ -77,7 +77,7 @@ export class BlogController {
|
|||||||
throw new BadRequestException('文章不存在或未公开');
|
throw new BadRequestException('文章不存在或未公开');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.blogService.getComments(id);
|
return await this.blogService.getComments(blog);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 该接口允许匿名评论,但仍需验证userId合法性
|
// 该接口允许匿名评论,但仍需验证userId合法性
|
||||||
|
|||||||
@@ -95,14 +95,9 @@ export class BlogService {
|
|||||||
await this.blogRepository.increment({ id }, 'viewCount', 1);
|
await this.blogRepository.increment({ id }, 'viewCount', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getComments(blogId: string) {
|
async getComments(blog: Blog) {
|
||||||
const blog = await this.findById(blogId);
|
|
||||||
if (!blog) {
|
|
||||||
throw new Error('文章不存在');
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.blogCommentRepository.find({
|
return this.blogCommentRepository.find({
|
||||||
where: { blog },
|
where: { blog: { id: blog.id } },
|
||||||
relations: ['user'],
|
relations: ['user'],
|
||||||
order: {
|
order: {
|
||||||
createdAt: 'DESC',
|
createdAt: 'DESC',
|
||||||
|
|||||||
Reference in New Issue
Block a user