Skip to content

Commit

Permalink
fix: 채팅 페이지네이션 이슈 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
juyeong-s committed Oct 20, 2024
1 parent 9d6ddfb commit 86c6617
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/room/room.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,30 @@ export class RoomController {
@UseGuards(JwtAuthGuard)
public async searchChats(
@Param('id') roomId: string,
@Query() { page, size }: { page: string; size: string },
@Query() { page: _page, size: _size }: { page: string; size: string },
) {
const [page, size] = [Number(_page), Number(_size)];

const chats = await this.service.searchChat(roomId, {
page: Number(page),
size: Number(size),
page,
size,
});
const prevPage = page - 1;
const hasPrevious =
prevPage === -1
? false
: !!(await this.service.searchChat(roomId, {
page: prevPage,
size,
}));
const next = await this.service.searchChat(roomId, {
page: page + 1,
size,
});
const prevPage = Number(page) - 1 < 0 ? 0 : Number(page) - 1;
const hasPrevious = !!(await this.service.searchChat(roomId, {
page: prevPage,
size: 1,
}));
const hasNext = !!(await this.service.searchChat(roomId, {
page: Number(page) + 1,
size: 1,
}));
return new BaseResponse({
content: chats.map((chat) => new ChatDto(chat)),
currentPageNumber: page,
hasNext,
hasNext: !!next.length,
hasPrevious,
pageSize: size,
});
Expand Down

0 comments on commit 86c6617

Please sign in to comment.