prisma-paginate icon indicating copy to clipboard operation
prisma-paginate copied to clipboard

Pagination doesnt return nextPage, hasNextPage or any Getter

Open masterbater opened this issue 2 years ago • 2 comments

Hello Morning to you I got this weird behavior when Im using a library that uses native Response

When I console.log, I got this result and when I return it response json it strips out fields nextPage, hasNextPage, etc

{
  limit: 5,
  page: 1,
  count: 6,
  exceedCount: false,
  exceedTotalPages: false,
  result: [
    {
      id: 1
    }, {
      id: 2
    }, {
      id: 3
    }, {
      id: 4
    }, {
      id: 5
    }
  ],
  nextPage: [Function: nextPage],
  hasNextPage: [Getter],
  hasPrevPage: [Getter],
  totalPages: [Getter]
}

masterbater avatar Aug 14 '23 06:08 masterbater

Hello,

I'm facing the same issue too.

ishigami avatar Oct 23 '23 14:10 ishigami

The cause looks to be that the Pagination class doesn't export a toJson method to return the values instead of the getters/functions.

Its an easy PR but haven't had a chance to do myself.

A temporary work around I found was to manually assign the keys I needed to the response:

const paginatedUsers =  await paginatedPrisma.users.paginate({ limit: 10, 0 });

return json({ 
users: {
 ...paginatedUsers, 
nextPage: paginatedUsers.nextPage,  
hasNextPage: paginatedUsers.hasNextPage, 
hasPrevPage: paginatedUsers.hasPrevPage,
totalPages: paginatedUsers.totalPages} 
});

mindofjonas avatar Nov 10 '23 22:11 mindofjonas