The snippet of API code I have written is as follows:
var keystone = require('keystone');
var async = require('async');
var Order = keystone.list('Order');
exports = module.exports = function (req, res) {
Order.paginate ({page: req.query.page || 1, perPage: 100})
.where ("application", req.params.id)
.exec (function (err, results) {
return res.apiResponse({
success: true,
total: results.total,
length: results.results.length
});
});
}
//Request
// https://myapp.com/api/application/56d18490709714717834e913
//Returns:
// {"success":true,"total":73,"length":20}ID '56d18...' is 20.
However, the pagination is all based on the 'total', which is incorrect. Basically the search 'filters' I am applying seem to be ignored by the paginate function and I don't know why.
Is there something I am doing wrong here? Should the 'paginate' function be called somewhere else?
Thanks!
exports = module.exports = function (req, res) {
Order.paginate ({
page: req.query.page || 1,
perPage: 5,
filters: {'application':req.params.id}
})
.exec (function (err, results) {
return res.apiResponse({
success: true,
total: results.total,
length: results.results.length
});
});
}
//Request
// https://myapp.com/api/application/56d18490709714717834e913
//Returns:
// {"success":true,"total":20,"length":20}