meta not populated correctly when adding custom properties
Closed this issue · 3 comments
I set the totalCount on the request object. If I do not use custom properties, I get the correct meta data. Total rows in the table are 239. See below.
Response
return reply(results);
Data in browser (using Postman)
{ "meta": { "count": 1, "pageCount": 239, "totalCount": 239, "next": "http://localhost.localdomain:4050/world/country?_limit=1&_page=2", "self": "http://localhost.localdomain:4050/world/country?_limit=1&_page=1", "previous": null, "first": "http://localhost.localdomain:4050/world/country?_limit=1&_page=1", "last": "http://localhost.localdomain:4050/world/country?_limit=1&_page=239" }, "results": [ { "code": "AFG", "name": "Afghanistan", } ] }
When I set custom properties, the pageCount and totalCount are 0 and next and last links are null.
Response
return reply.paginate({ results: results, otherKey: 'value', otherKey2: 'value2' }, 0, { key: 'results' });
Data in browser (using Postman)
{ "meta": { "count": 1, "pageCount": 0, "totalCount": 0, "next": null, "self": "http://localhost.localdomain:4050/world/country?_limit=1&_page=1", "previous": null, "first": "http://localhost.localdomain:4050/world/country?_limit=1&_page=1", "last": null }, "results": [ { "code": "AFG", "name": "Afghanistan", } ], "otherKey": "value", "otherKey2": "value2" }
I looked in the tests and saw that the test only checks if the meta and results are populated. It does not check if the pageCount, totalCount, and the links are populated correctly.
return reply.paginate({ results: results, otherKey: 'value', otherKey2: 'value2' }, 0, { key: 'results' });
Here you say that totalCount
is 0, so pageCount
is 0 as well.
In the example on the README
I am doing: return reply.paginate({ results: [], otherKey: 'value', otherKey2: 'value2' }, 0, { key: 'results' });
with 0 as well because the results is empty.
The plugin search for the totalCount
sent with the reply.paginate
method, if it doesn't find it, it'll check the request object. If you really want to use the request object, change 0 to null/undefined.
I think I should change the documentation to make it more clear and add more examples.
That solved it. I was not sure what the 0 was for.
Thank you!!!