skirda-backend/api/CustomersPage/index.js
2022-08-24 15:08:22 +03:00

24 lines
718 B
JavaScript

const customers = require('../data/customers.json');
module.exports = async function (context, req) {
const { skip: skipVal, top: topVal } = context.bindingData;
const skip = (isNaN(skipVal)) ? 0 : +skipVal;
let top = (isNaN(topVal)) ? 10 : skip + (+topVal);
if (top > customers.length) {
top = skip + (customers.length - skip);
}
console.log(`Skip: ${skip} Top: ${top}`);
var pagedCustomers = customers.slice(skip, top);
context.res = {
// status: 200, /* Defaults to 200 */
headers : {
'Content-Type': 'application/json',
'X-InlineCount': customers.length
},
body: pagedCustomers
};
}