prisma-paginate
prisma-paginate copied to clipboard
Pagination doesnt return nextPage, hasNextPage or any Getter
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]
}
Hello,
I'm facing the same issue too.
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}
});