Closed Nickynodejs closed 5 years ago
I have same problem。。。。how to resolve this problem。。。。"@hapi/hapi": "^18.4.0","hapi-pagination": "^3.0.0"
@wisdomQiuqiu What does your response look like? You should have something like return { results: [], totalCount: 10 }
in your method.
this is my code
const { rows: results, count: totalCount } = await models.shops.findAndCountAll({ attributes: ["id", "name"], limit: request.query.limit, offset: (request.query.page - 1) * request.query.limit }); return { code: 200, content: { currentList: results, totalCount } };
What causes this problem??
Based on that code it should look more like this.
const { rows: results, count: totalCount } = await models.shops.findAndCountAll({
attributes: ["id", "name"],
limit: request.query.limit,
offset: (request.query.page - 1) * request.query.limit
});
return { results, totalCount };
The results
and totalCount
properties have to be at the root of the response.
How do i want to nest one more layer??
You can't but you can add custom properties. Just read the documentation for https://github.com/fknop/hapi-pagination#hpaginatearrayobject-totalcount-options--.
ok,thank you
"hapi": "^18.1.0", "hapi-pagination": "^2.1.0",Operation error reporting。
Debug: internal, implementation, error AssertionError [ERR_ASSERTION]: The results must be an array