nfp_sites/app/api/pagination.js

17 lines
375 B
JavaScript
Raw Normal View History

2019-09-14 19:03:38 +00:00
const parse = require('parse-link-header')
2019-10-01 11:35:00 +00:00
const common = require('./common')
2019-09-14 19:03:38 +00:00
exports.fetchPage = function(url) {
2019-10-01 11:35:00 +00:00
return common.sendRequest({
2019-09-14 19:03:38 +00:00
method: 'GET',
url: url,
}, true)
2019-10-01 11:35:00 +00:00
.then(function(result) {
2019-09-14 19:03:38 +00:00
return {
data: result.data,
links: parse(result.headers.link || ''),
total: Number(result.headers.pagination_total || '0'),
}
})
}