Skip to content

Commit a6238df

Browse files
authored
Merge pull request #185 from umc-commit/bug/184-chatroom-delete
[BUG] 채팅방 삭제 수정
2 parents 361e3d7 + 4acda06 commit a6238df

File tree

4 files changed

+72
-28
lines changed

4 files changed

+72
-28
lines changed

src/chat/controller/chatroom.controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const getChatroom = async (req, res, next) => {
3131
const dto = new GetChatroomDto({
3232
userId,
3333
accountId: BigInt(req.user.accountId),
34+
role: req.user.role,
3435
});
3536

3637
const chatrooms = await ChatroomService.getChatroomsByUserId(dto);

src/chat/dto/chatroom.dto.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ export class CreateChatroomDto {
77
}
88

99
export class GetChatroomDto {
10-
constructor({ userId, accountId }) {
10+
constructor({ userId, accountId, role}) {
1111
this.userId = BigInt(userId);
1212
this.accountId = BigInt(accountId);
13+
this.role = role;
1314
}
1415
}
1516

src/chat/repository/chatroom.repository.js

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,77 @@ export const ChatroomRepository = {
2222
});
2323
},
2424

25-
async findChatroomsByUser(userId) {
25+
async findChatroomsByUser(account) {
2626
// 1. 채팅방 기본 정보 + 마지막 메시지(내용, 생성시간, id) 조회
27-
const chatrooms = await prisma.chatroom.findMany({
28-
where: { userId },
29-
include: {
30-
artist: {
31-
select: {
32-
id: true,
33-
nickname: true,
34-
profileImage: true,
35-
}
27+
let chatrooms;
28+
29+
if (account.role === "client") {
30+
// ✅ 클라이언트가 보는 채팅방
31+
chatrooms = await prisma.chatroom.findMany({
32+
where: {
33+
userId: BigInt(account.userId),
34+
hiddenUser: false,
3635
},
37-
commission: {
38-
select: {
39-
id: true,
40-
title: true,
41-
}
36+
include: {
37+
artist: {
38+
select: {
39+
id: true,
40+
nickname: true,
41+
profileImage: true,
42+
},
43+
},
44+
commission: {
45+
select: {
46+
id: true,
47+
title: true,
48+
},
49+
},
50+
chatMessages: {
51+
orderBy: { createdAt: "desc" },
52+
take: 1,
53+
select: {
54+
id: true,
55+
content: true,
56+
createdAt: true,
57+
},
58+
},
4259
},
43-
chatMessages: {
44-
orderBy: { createdAt: "desc" },
45-
take: 1,
46-
select: {
47-
id: true,
48-
content: true,
49-
createdAt: true,
50-
}
51-
}
52-
}
53-
});
60+
});
61+
} else if (account.role === "artist") {
62+
// ✅ 아티스트가 보는 채팅방
63+
chatrooms = await prisma.chatroom.findMany({
64+
where: {
65+
artistId: BigInt(account.artistId),
66+
hiddenArtist: false,
67+
},
68+
include: {
69+
user: {
70+
select: {
71+
id: true,
72+
nickname: true,
73+
profileImage: true,
74+
},
75+
},
76+
commission: {
77+
select: {
78+
id: true,
79+
title: true,
80+
},
81+
},
82+
chatMessages: {
83+
orderBy: { createdAt: "desc" },
84+
take: 1,
85+
select: {
86+
id: true,
87+
content: true,
88+
createdAt: true,
89+
},
90+
},
91+
},
92+
});
93+
} else {
94+
return [];
95+
}
5496

5597
// 2. 마지막 메시지 ID 목록 수집
5698
const messageIds = chatrooms

src/chat/service/chatroom.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const ChatroomService = {
5151
const user = await UserRepository.findUserById(dto.userId);
5252
if (!user) throw new UserNotFoundError({ userId: dto.userId });
5353

54-
const chatrooms = await ChatroomRepository.findChatroomsByUser(dto.userId);
54+
const chatrooms = await ChatroomRepository.findChatroomsByUser(dto);
5555

5656
// 1. thumbnail 한 번에 조회 (BigInt 변환)
5757
const commissionIds = chatrooms.map(r => BigInt(r.commission.id));

0 commit comments

Comments
 (0)