Попытка вернуть логическое значение, если объект rejectMessage содержит код, который я указал в методе checkErrorCodes. он должен возвращать значение true, еслилокация сопоставления соответствует своему не возвращаемому логическому значению, он переустанавливает всю функцию isError. Любая идея или лучший подход, чтобы сделать это?
transformPrice.js
function transformPrice(oldDrugPrice) {
let drugPrice = {
"drugName": "Metformin",
"mailPrice": {
"copayEmployer": "N/A",
"totalQuantity": "90.0",
"rejectMessage": [{
"settlementCode": "99",
"settlementDesc": "Not Covered: Call us - System could not process your request. Call us at the toll-free number on your benefit ID card.||Sin cobertura: Llámenos - El sistema no pudo procesar su solicitud. Llame al número gratuito que figura en su tarjeta de identificación de beneficios."
}]
},
"retailPrice": {
"copayEmployer": "N/A",
"totalQuantity": "30.0"
}
},
if (drugPrice.retailPrice.rejectMessage || drugPrice.mailPrice.rejectMessage.length ){
const retailRejecrMsg = drugPrice.retailPrice.rejectMessage;
const mailPriceMsg = drugPrice.mailPrice.rejectMessage;
const retailErr = isErrorPresent(retailRejecrMsg);
const mailErr =isErrorPresent(mailPriceMsg);
}
return drugPrice;
}
Метод isErrorPresent
function isErrorPresent (price) {
const isError = function (element) {
const bRet = checkErrorCodes(element);
return (element.hasOwnProperty('settlementCode') && bRet)
}
return isError;
}
метод checkErrorCodes
function checkErrorCodes(el){
let bRet = false;
const errorCodes = [
10015,
2356,
225,
224,
99
]
for (const err of errorCodes){
if (err === el.settlementCode){
bRet = true;
}
}
return bRet;
}