fknop / hapi-pagination

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

question: Shouldn't hapi-pagination filter the results? #11

Closed pcdevil closed 8 years ago

pcdevil commented 8 years ago

Hello,
I want to use hapi-pagination in my project and first thing I noticed the library doesn't narrow down the results based on the page and limit properties on request.query.

I was assumed the package does this so I don't need to do it myself because it would create a boilerplate to do it all my route, but I also don't see any information about this in documentation.

Can you give me a hint how to use it without write something like this in my every handler?:

var filteredResults = filterResults(results, request.query.page, request.query.limit);

(Sorry, this isn't an issue in the general sense but had to ask it.)

fknop commented 8 years ago

Hi,

No it doesn't do that. The plugin can't assume what database or ORM you're using. It can't returns the results for you. It just takes care of the metadata.

If you want to create a boilerplate for your ORM, you should do a method yourself.

pcdevil commented 8 years ago

Thank you the information.

I dug into the hapijs API documentation and found onPreResponse extension point to mutate my results.