skirda-backend/api/CustomerCreate/index.js

17 lines
557 B
JavaScript
Raw Normal View History

2022-08-24 12:08:22 +00:00
const customers = require('../data/customers.json');
module.exports = async function (context, req) {
let postedCustomer = req.body;
let maxId = Math.max.apply(Math, customers.map((cust) => cust.id));
postedCustomer.id = ++maxId;
postedCustomer.gender = (postedCustomer.id % 2 === 0) ? 'female' : 'male';
customers.push(postedCustomer);
context.res = {
// status: 200, /* Defaults to 200 */
headers: {
'Content-Type': 'application/json'
},
body: postedCustomer
};
}