获取评论时,返回的user信息仅包含必要字段

This commit is contained in:
2025-06-23 09:23:26 +08:00
parent e4dba6103e
commit 524f99ef9d

View File

@@ -96,13 +96,25 @@ export class BlogService {
}
async getComments(blog: Blog) {
return this.blogCommentRepository.find({
const comments = await this.blogCommentRepository.find({
where: { blog: { id: blog.id } },
relations: ['user'],
order: {
createdAt: 'DESC',
},
});
return comments.map(comment => {
const { blog, user, ...rest } = comment;
return {
...rest,
user: user ? {
userId: user.userId,
username: user.username,
nickname: user.nickname,
} : null,
}
})
}
async createComment(comment: Partial<BlogComment>) {