From c7c4c9c8438910a72c0637b437c4dbb4ce719c9c Mon Sep 17 00:00:00 2001 From: casulit Date: Fri, 18 Oct 2024 13:04:26 +0800 Subject: [PATCH] refactor(server): Nest pagination details in API response json --- server.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server.ts b/server.ts index 3aa6873..f24ec61 100644 --- a/server.ts +++ b/server.ts @@ -193,19 +193,21 @@ app.get("/api/properties", async (c: Context) => { const totalListingRecords = counterResult.count; const pageNo = parseInt(query.page); const pageSize = parseInt(query.page_size); - + const totalPages = Math.ceil(totalListingRecords / pageSize); const nextPage = pageNo < totalPages ? pageNo + 1 : null; const previousPage = pageNo > 1 ? pageNo - 1 : null; - - return c.json({ + + return c.json({ data: postgres.rows, - total: totalListingRecords, - page: pageNo, - page_size: pageSize, - total_pages: totalPages, - next_page: nextPage, - previous_page: previousPage + pagination: { + total: totalListingRecords, + page: pageNo, + page_size: pageSize, + total_pages: totalPages, + next_page: nextPage, + previous_page: previousPage, + }, }); });