fknop / hapi-pagination

Hapi plugin to handle "custom" pagination
MIT License
63 stars 36 forks source link

Previous and Self links do not work when default is 0 #81

Open dumbbaldmonkey opened 4 years ago

dumbbaldmonkey commented 4 years ago

When setting a default page of 0, which is what Postgres uses as its first page, the self/preivous links are not working as expected.

The self link is null and the previous link goes to page=-1

This is due to the if(!page) check in the getUri method. Could this be changed to be < the default value? I can make a PR if you think this is a reasonable fix.

icenine457 commented 4 years ago

I believe this PR addresses your concerns (I ran into this issue myself): https://github.com/fknop/hapi-pagination/pull/83

It introduces an boolean option at the root of the configuration to allow for using a zero index when paginating. I've defaulted it to false in order to ensure backwards-compatibility, and included tests demonstrating the behavior when it is both false and true.

icenine457 commented 4 years ago

@dumbbaldmonkey Looks like the related PR was merged FYI (thanks @fknop!)