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

17 lines
557 B
JavaScript

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
};
}