Skip to content

Commit a31bc03

Browse files
authored
Merge pull request #179 from umc-commit/bug/178-chatroom
[BUG] 커미션 아이디 에러
2 parents 42ae10b + 980b2d3 commit a31bc03

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/chat/service/chatroom.service.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,23 @@ export const ChatroomService = {
5353

5454
const chatrooms = await ChatroomRepository.findChatroomsByUser(dto.userId);
5555

56-
// thumbnail 한 번에 조회
57-
const commissionIds = chatrooms.map(r => r.commission.id);
58-
const images = await CommissionRepository.findImagesByCommissionId(commissionIds);
59-
const thumbnailMap = Object.fromEntries(images.map(img => [img.targetId.toString(), img.imageUrl]));
56+
// 1. thumbnail 한 번에 조회 (BigInt 변환)
57+
const commissionIds = chatrooms.map(r => BigInt(r.commission.id));
58+
const images = await CommissionRepository.findImagesByCommissionIds(commissionIds);
59+
const thumbnailMap = Object.fromEntries(
60+
images.map(img => [img.targetId.toString(), img.imageUrl])
61+
);
6062

61-
// DTO 생성
63+
// 2. DTO 생성
6264
const result = [];
6365
for (const room of chatrooms) {
64-
room.commission.thumbnail = thumbnailMap[room.commission.id.toString()] || null;
66+
room.commission.thumbnail = thumbnailMap[BigInt(room.commission.id).toString()] || null;
6567

66-
// 방마다 unreadCount 조회
67-
const unreadCount = await ChatRepository.countUnreadMessages(room.id, dto.accountId);
68+
// 방마다 unreadCount 조회 (BigInt 변환)
69+
const unreadCount = await ChatRepository.countUnreadMessages(
70+
BigInt(room.id),
71+
BigInt(dto.accountId)
72+
);
6873

6974
result.push(new ChatroomListResponseDto(room, unreadCount));
7075
}

src/commission/repository/commission.repository.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ export const CommissionRepository = {
6868
});
6969
},
7070

71+
async findImagesByCommissionIds(commissionIds) {
72+
return await prisma.image.findMany({
73+
where: {
74+
target: 'commissions',
75+
targetId: { in: commissionIds }, // 배열 처리
76+
},
77+
orderBy: { orderIndex: 'asc' },
78+
});
79+
},
80+
7181
/**
7282
* 커미션 ID로 신청폼 조회 (작가 정보 포함)
7383
*/

0 commit comments

Comments
 (0)