fknop / hapi-pagination

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

Wrong or missing metadata #64

Closed ferrao closed 6 years ago

ferrao commented 6 years ago

I am getting some weird metadata for the query https://localhost:8081/api/user?limit=1&page=2 on a collection of 3 elements:

{
    "meta": {
        "count": 1,
        "pageCount": null,
        "totalCount": null,
        "next": null,
        "previous": "https://localhost:8081/api/user?limit=1&page=1",
        "self": "https://localhost:8081/api/user?limit=1&page=2",
        "first": "https://localhost:8081/api/user?limit=1&page=1",
        "last": null
    },
    "results": [
        {
            "id": 2,
            "username": "test",          
        }
    ]
}

All those null values there just seem wrong to me. And If I set meta.location='header' its even worse, I get no headers whatsoever. Looking at ext.js I see:

if (totalCount > currentLimit && results.length > 0) {
   // headers are set
}

Considering totalCount always gets here undefined this condition always evaluates to false and hence no headers..

Am I missing something, or is hapi-pagination broken? If that is the case, I am happy to work on fixing it.

fknop commented 6 years ago

Are you using the paginate method to pass the total count?

ferrao commented 6 years ago

Not at all @fknop, but just realised I should, please ignore this and thank you for this nice module that is now doing exactly what I want :)

fknop commented 6 years ago

No problem :)