修复评论时会暴露用户所有字段的问题

This commit is contained in:
2025-06-23 09:25:15 +08:00
parent 524f99ef9d
commit ab3ed103db

View File

@@ -120,8 +120,15 @@ export class BlogService {
async createComment(comment: Partial<BlogComment>) { async createComment(comment: Partial<BlogComment>) {
const newComment = this.blogCommentRepository.create(comment); const newComment = this.blogCommentRepository.create(comment);
const savedComment = await this.blogCommentRepository.save(newComment, {}); const savedComment = await this.blogCommentRepository.save(newComment, {});
const { blog, ...commentWithoutBlog } = savedComment; const { blog, user, ...commentWithoutBlog } = savedComment;
return commentWithoutBlog; return {
...commentWithoutBlog,
user: user ? {
userId: user.userId,
username: user.username,
nickname: user.nickname,
} : null,
};
} }
hashPassword(password: string) { hashPassword(password: string) {