Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
fix : 대댓글 에러 수정 (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
yewonahn committed Feb 18, 2024
2 parents d9e491d + 95c1fc0 commit a1b4f77
Showing 1 changed file with 13 additions and 67 deletions.
80 changes: 13 additions & 67 deletions src/signature/signature.comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,82 +78,26 @@ export class SignatureCommentService{
signatureId: number,
) {

// cursorId 이용해서 마지막으로 보낸 댓글 정보 알아내기
const lastComment = await SignatureCommentEntity.findOne({
// 1. 'cursorId'부터 오름차순 정령된 댓글 'take'만큼 가져오기
const [comments, total] = await SignatureCommentEntity.findAndCount({
take: cursorPageOptionsDto.take,
where: {
signature: { id: signatureId },
id: cursorPageOptionsDto.cursorId
parentComment: { id: cursorPageOptionsDto.cursorId ? MoreThan(cursorPageOptionsDto.cursorId) : null },
},
relations: {parentComment: true}
});

let comments = [];
let total: number = 0;

// lastComment 가 자신과 부모가 같으면서 자신보다 depth 가 깊은 대댓글이 있는, 대댓글인지 확인
let sendData = new SignatureCommentEntity();

const check = await SignatureCommentEntity.find({
where: {
signature: { id: signatureId },
parentComment: {id: lastComment.parentComment.id},
id: MoreThan(lastComment.id)
relations: {
user: { profileImage: true },
parentComment: true,
signature:{
user: true,
}
},
order: {
parentComment: { id: "ASC" as any,},
},
});

// -1) 있는 경우
if(!!check) {
sendData = check[0];

const [commentEntities, totalNumber] = await SignatureCommentEntity.findAndCount({
take: cursorPageOptionsDto.take,
where: {
signature: { id: signatureId },
id: MoreThan(sendData.id),
},
relations: {
user: { profileImage: true },
parentComment: true,
signature:{
user: true,
}
},
order: {
parentComment: { id: "ASC" as any,},
},
});
comments = commentEntities;
total = totalNumber;
}

else {
// -2) 없는 경우
// 'cursorId' 부터 오름차순 정렬된 댓글 'take' 만큼 가져오기
const [commentEntities, totalNumber] = await SignatureCommentEntity.findAndCount({
take: cursorPageOptionsDto.take,
where: {
signature: { id: signatureId },
parentComment: { id: cursorPageOptionsDto.cursorId ? MoreThan(cursorPageOptionsDto.cursorId) : null },
},
relations: {
user: { profileImage: true },
parentComment: true,
signature:{
user: true,
}
},
order: {
parentComment: { id: "ASC" as any,},
},
});
comments = commentEntities;
total = totalNumber;
}

// 2. 댓글 response dto 에 담기
// 2. 댓글 response dto에 담기
const result = await Promise.all(comments.map(async (comment) => {
const writerProfile = new GetCommentWriterDto();
const getCommentDto = new GetSignatureCommentDto();
Expand Down Expand Up @@ -225,6 +169,8 @@ export class SignatureCommentService{
{ cursorPageOptionsDto, total, hasNextData, cursor });

return new CursorPageDto( result, cursorPageMetaDto );


}

async patchSignatureComment( // 댓글 수정하기
Expand Down

0 comments on commit a1b4f77

Please sign in to comment.