diff --git a/src/chat/repositories/chat.repository.ts b/src/chat/repositories/chat.repository.ts index 81a9629..20a009d 100644 --- a/src/chat/repositories/chat.repository.ts +++ b/src/chat/repositories/chat.repository.ts @@ -90,7 +90,7 @@ export class ChatRepository { cursor: { message_id: cursor }, } : {}), - orderBy: { message_id: "asc" }, + orderBy: { message_id: "desc" }, include: { attachments: true }, }), // 해당 방의 전체 메시지 개수 조회 @@ -99,8 +99,11 @@ export class ChatRepository { }), ]); + const hasNextPage = messages.length > limit; + const actualMessages = hasNextPage ? messages.slice(0, -1) : messages; + return { - messages, + messages: actualMessages, totalCount, }; } diff --git a/src/chat/routes/chat.route.ts b/src/chat/routes/chat.route.ts index 49c7a3b..ed7db84 100644 --- a/src/chat/routes/chat.route.ts +++ b/src/chat/routes/chat.route.ts @@ -69,7 +69,7 @@ router.post("/rooms", authenticateJwt, createOrGetChatRoom); * summary: 채팅방 상세 조회 * description: > * 채팅방 상세 정보(상대 정보/차단 상태/메시지 목록/페이지 정보)를 조회합니다.
- * 메시지는 오래된 순(ASC)으로 반환되며, cursor 기반으로 과거 메시지를 추가로 불러올 수 있습니다. + * 메시지는 최신순(DESC)으로 반환되며, cursor 기반으로 과거 메시지를 추가로 불러올 수 있습니다. * tags: [Chat] * security: * - jwt: []