new

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.3 kB
1
Indexable
Never
var input = JSON.parse(Input);

var body = JSON.parse(input.input.body);

var newBody = {};

var date = new Date();

var origination = {};
origination["organizationBranchCode"] = body["origination"]["org-unit"];

var customerData = {};
customerData["customerId"] = body["customer-number"];

var amount = {};
if(body["primary-currency"] != null)
amount["currency"] = body["primary-currency"];
if(body["approved-amount"] != null)
amount["amount"] = body["approved-amount"];

var feeList = [];
var fee = {};
var fixedAmount = {};
if(body["commercial-terms"]["fees"][0]["fixed-amount"]["code"]!=null)
fixedAmount["currency"] = body["commercial-terms"]["fees"][0]["fixed-amount"]["code"];
if(body["commercial-terms"]["fees"][0]["fixed-amount"]["amount"] != null)
fixedAmount["amount"] = body["commercial-terms"]["fees"][0]["fixed-amount"]["amount"];

var minAmount = {};
if(body["commercial-terms"]["fees"][0]["lower-limit"]["code"] != null)
minAmount["currency"] = body["commercial-terms"]["fees"][0]["lower-limit"]["code"];
if(body["commercial-terms"]["fees"][0]["lower-limit"]["amount"] != null)
minAmount["amount"] = body["commercial-terms"]["fees"][0]["lower-limit"]["amount"];

var maxAmount = {};
if(body["commercial-terms"]["fees"][0]["upper-limit"]["code"] != null)
maxAmount["currency"] = body["commercial-terms"]["fees"][0]["upper-limit"]["code"];
if(body["commercial-terms"]["fees"][0]["upper-limit"]["amount"] != null)
maxAmount["amount"] = body["commercial-terms"]["fees"][0]["upper-limit"]["amount"];

if(body["commercial-terms"]["fees"][0]["kind"] != null)
fee["type"] = body["commercial-terms"]["fees"][0]["kind"];
if(fixedAmount != null)
fee["fixedAmount"] = fixedAmount;
if(body["commercial-terms"]["fees"][0]["percentage"] != null)
fee["percentageAmount"] = body["commercial-terms"]["fees"][0]["percentage"];
if(minAmount != null)
fee["minAmount"] = minAmount;
if(maxAmount != null)
fee["maxAmount"] = maxAmount;

feeList.push(fee);

var accounts = [];
var account = {};
if(body["accounts"][0]["account-number"] != null)
account["accountNumber"] = body["accounts"][0]["account-number"];
accounts.push(account);

var schedule = {};
if(body["nominal-apr"] != null)
schedule["nominalInterestRate"] = body["nominal-apr"];

if(origination != null)
newBody["origination"] = origination;
if(customerData != null)
newBody["customerData"] = customerData;
if(body["credit-facility-number"] != null)
newBody["creditFacilityNumber"] = body["credit-facility-number"];
if(body["kind"] != null)
newBody["productType"] = body["kind"];
if(amount != null)
newBody["approvedAmount"] = amount;
if(body["disbursement-instructions"]["disbursement-date"]!=null)
newBody["utilizationFromDate"] = body["disbursement-instructions"]["disbursement-date"];
if(body["disbursement-instructions"]["disbursement-date"] != null)
newBody["utilizationUntilDate"] = body["disbursement-instructions"]["disbursement-date"];
if(body["contract-date"] != null)
newBody["contractDate"] = body["contract-date"];
if(accounts != null)
newBody["accounts"] = accounts;
if(schedule != null)
newBody["schedule"] = schedule;
if(feeList != null)
newBody["fees"] = feeList;


var req = {
    url:"api/v1/loans/creation-requests",
   body: newBody
 }

return JSON.stringify(req);