Skip to content

Commit b732e19

Browse files
committed
feat: 게시글 댓글 로직 변경
1 parent 3b1d76f commit b732e19

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/post-comment/post-comment.controller.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ export class PostCommentController {
6161
): Promise<BaseResponse<GetCommentsDto>> {
6262
const currentUserId = req.user.id;
6363

64-
const comments = await this.postCommentService.getPostComments(postId);
64+
const comments = await this.postCommentService.getPostComments(
65+
postId,
66+
currentUserId,
67+
);
6568

6669
const commenteResponse: GetCommentsDto = {
6770
comments: comments.map((comment) => ({

src/post-comment/post-comment.service.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { forwardRef, Inject, Injectable } from '@nestjs/common';
22
import { PostComment } from 'src/common/entities/post-comment.entity';
3-
import { QueryRunner } from 'typeorm';
3+
import { Not, QueryRunner } from 'typeorm';
44
import { InjectRepository } from '@nestjs/typeorm';
55
import { Repository } from 'typeorm';
66
import { CreateCommentDto } from './dtos/create-comment.dto';
@@ -85,16 +85,27 @@ export class PostCommentService {
8585
}
8686

8787
// 댓글 리스트 조회
88-
async getPostComments(postId: number): Promise<PostComment[]> {
88+
async getPostComments(
89+
postId: number,
90+
currentUserId: number,
91+
): Promise<PostComment[]> {
8992
return await this.postCommentRepository.find({
90-
where: { post: { id: postId }, status: 'activated' },
93+
where: {
94+
post: { id: postId },
95+
status: 'activated',
96+
user: { status: 'activated', id: Not(currentUserId) },
97+
},
9198
relations: ['user'],
9299
});
93100
}
94101

95102
private async findCommentById(commentId: number): Promise<PostComment> {
96103
const comment = await this.postCommentRepository.findOne({
97-
where: { id: commentId, status: 'activated' },
104+
where: {
105+
id: commentId,
106+
status: 'activated',
107+
user: { status: 'activated' },
108+
},
98109
relations: ['user'],
99110
});
100111

0 commit comments

Comments
 (0)