Copy let taxObj = {
type: 'TAX_' + taxRateBrackets[i].taxCode,
amount: {
value: taxRateBrackets[i].bracketAmount
}
}
It also might be more beneficial to separate the conditional / object building logic into a separate (non-exported) method that does the mapping. Like this:
Copy function mapTaxResponse (countryCode, taxRateBracket, currencyCode) {
if (hasVatTax(countryCode, taxRateBracket)) {
return getVatTax(taxRateBracket, currencyCode)
} else {
return getNonVatTax(taxRateBracket, currencyCode)
}
}
function hasVatTax (countryCode, taxRateBracket) {
if (!vatcountryCodes.includes(countryCode)) {
return false
}
let taxRateAmount = _.get(taxRateBracket, 'taxRateAmount')
let taxRateId = _.get(taxRateBracket, 'taxRateId')
return (taxRateAmount !== null
&
&
taxRateId !== null)
}
function getVatTax (taxRateBracket, currencyCode) {
return {
type: `TAX_${taxRateBracket.taxCode}`,
amount: {
code: currencyCode
},
taxRate: {
amount: {
value: taxRateBracket.taxRateAmount
}
},
taxRecord: taxRateBracket.taxRateId
}
}
function getNonVatTax (taxRateBracket, currencyCode) {
return {
type: `TAX_${taxRateBracket.taxCode},
amount: {}
}
}
Copy function taxBuilder (rq, taxRateBrackets) {
return taxRateBrackets.map(taxRateBracket =>
mapTaxResponse(rq.countryCode, taxRateBracket, rq.currencyCode))
}