Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/chat/service/chatroom.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,23 @@ export const ChatroomService = {

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

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

// DTO 생성
// 2. DTO 생성
const result = [];
for (const room of chatrooms) {
room.commission.thumbnail = thumbnailMap[room.commission.id.toString()] || null;
room.commission.thumbnail = thumbnailMap[BigInt(room.commission.id).toString()] || null;

// 방마다 unreadCount 조회
const unreadCount = await ChatRepository.countUnreadMessages(room.id, dto.accountId);
// 방마다 unreadCount 조회 (BigInt 변환)
const unreadCount = await ChatRepository.countUnreadMessages(
BigInt(room.id),
BigInt(dto.accountId)
);

result.push(new ChatroomListResponseDto(room, unreadCount));
}
Expand Down
10 changes: 10 additions & 0 deletions src/commission/repository/commission.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ export const CommissionRepository = {
});
},

async findImagesByCommissionIds(commissionIds) {
return await prisma.image.findMany({
where: {
target: 'commissions',
targetId: { in: commissionIds }, // 배열 처리
},
orderBy: { orderIndex: 'asc' },
});
},

/**
* 커미션 ID로 신청폼 조회 (작가 정보 포함)
*/
Expand Down