diff --git a/src/chat/repositories/chat.repository.ts b/src/chat/repositories/chat.repository.ts index 3edc147..5d1966e 100644 --- a/src/chat/repositories/chat.repository.ts +++ b/src/chat/repositories/chat.repository.ts @@ -18,6 +18,13 @@ export class ChatRepository { user_id1: userId1, user_id2: userId2, last_message_id: null, + // 참여자 생성 + participants: { + create: [ + { user_id: userId1}, + { user_id: userId2}, + ], + } }, }); } @@ -111,6 +118,8 @@ export class ChatRepository { const where: Prisma.ChatParticipantWhereInput = { user_id: userId, left_at: null, // 나가지 않은 방 + chatRoom: { + is: { last_message_id: { not: null } } }, // 메시지가 있는 방 }; if (filter === "pinned") { @@ -123,16 +132,17 @@ export class ChatRepository { if (search && search.trim().length > 0) { where.chatRoom = { - participants: { - some: { - user_id: { not: userId }, - user: { - nickname: { - contains: search.trim(), + is: { + ...(where.chatRoom as any)?.is, + participants: { + some: { + user_id: { not: userId }, + user: { + nickname: {contains: search.trim()}, }, }, }, - }, + } }; } diff --git a/src/chat/routes/chat.route.ts b/src/chat/routes/chat.route.ts index 81f634c..5cfe2ad 100644 --- a/src/chat/routes/chat.route.ts +++ b/src/chat/routes/chat.route.ts @@ -68,7 +68,7 @@ router.post("/rooms", authenticateJwt, createOrGetChatRoom); * get: * summary: 채팅방 상세 조회 * description: > - * 채팅방 상세 정보(상대 정보/차단 상태/메시지 목록/페이지 정보)를 조회합니다. + * 채팅방 상세 정보(상대 정보/차단 상태/메시지 목록/페이지 정보)를 조회합니다.
* 메시지는 오래된 순(ASC)으로 반환되며, cursor 기반으로 과거 메시지를 추가로 불러올 수 있습니다. * tags: [Chat] * security: @@ -227,7 +227,8 @@ router.get("/rooms/:roomId", authenticateJwt, getChatRoomDetail); * get: * summary: 채팅방 목록 조회 * description: > - * 내 채팅방 목록을 조회합니다. + * 내 채팅방 목록을 조회합니다.
+ * 메세지가 존재하지 않으면 해당 채팅방은 목록에서 제외됩니다.
* filter(전체/안읽음/고정), search(상대 닉네임 검색), cursor 기반 페이징을 지원합니다. * tags: [Chat] * security: