From 72fd8d1a3cf37cdba8850d7bfc777b4abf7a3121 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Wed, 19 Feb 2025 13:55:08 -0500 Subject: [PATCH 1/2] Rewrite GetRecalPartNumber(s) helper method --- src/helpers/recal-helper.js | 12 ++++++++++++ src/store/index.js | 24 +++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/helpers/recal-helper.js b/src/helpers/recal-helper.js index c73755e8f..d43da5d34 100644 --- a/src/helpers/recal-helper.js +++ b/src/helpers/recal-helper.js @@ -58,3 +58,15 @@ export function getTopLevelPartsWithRecal(lineItems) { return lineItems.filter((li) => isRecalPartOrHasChildRecalPart(li)); } + +export function getRecalPartNumbers(glassPartsArray) { + if (glassPartsArray && glassPartsArray.length > 0) { + const topLevel = glassPartsArray.filter((gp) => isRecalPart(gp)).map((gp) => gp.partNumber); + + const children = glassPartsArray.map((gp) => getRecalPartNumbers(gp.childParts)).flat(); + + return [...topLevel, ...children]; + } else { + return []; + } +} diff --git a/src/store/index.js b/src/store/index.js index 03e8f339a..d52fea200 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -45,6 +45,7 @@ import { containsRecalParts, getTopLevelPartsWithRecal, isRecalPartOrHasChildRecalPart, + getRecalPartNumbers, } from "@/helpers/recal-helper"; import { externalParameterStatus } from "@/constants/external-parameters"; import { experimentSettings } from "@/constants/experiments"; @@ -1712,10 +1713,15 @@ export const actions = { var endPoint = `${endpoints.GetMobileFeePart.url}/?serviceType=${serviceType}&facilityType=${facilityType}&parentAccountNumber=${parentAccountNumber}&billToAccountNumber=${billToAccountNumber}&providerNumber=${providerNumber}&isItacOptimized=${isItacOptimized}&zipCode=${zipCode}`; - const recalPartNumber = getRecalPartNumber(order.lineItems?.glassParts[0]); + const recalPartNumbers = getRecalPartNumbers(order.lineItems?.glassParts); const carId = order.vehicle?.carId; - if (recalPartNumber && carId) { - endPoint = `${endPoint}&partNumbers=${recalPartNumber}&carId=${carId}`; + if (recalPartNumbers && recalPartNumbers.length > 0 && carId) { + let additionalQueryParams = ``; + for (let i = 0; i < recalPartNumbers.length; i++) { + additionalQueryParams += `&partNumbers[${i}]=4${recalPartNumbers[i]}`; + } + additionalQueryParams += `&carId=${carId}`; + endPoint += additionalQueryParams; } if (coverageStatus) { @@ -3760,15 +3766,3 @@ function getExternalParameterDefaultState() { function saveExternalParameterState(externalParameterState) { window.sessionStorage.setItem("externalParameterState", JSON.stringify(externalParameterState)); } - -//This function finds the recalibration part and returns the part number for it. -function getRecalPartNumber(glassPartsArray) { - const recalPart = glassPartsArray.childParts.find( - (item) => item.partType === partTypeStrings.ADAS_RECALIBRATION - ); - if (recalPart) { - return recalPart.partNumber; - } else { - return null; - } -} From fa48005be0cf2537259d15fc916fa2889c2f378a Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Wed, 19 Feb 2025 15:30:04 -0500 Subject: [PATCH 2/2] Fix typo --- src/store/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/index.js b/src/store/index.js index d52fea200..7a1f74732 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1718,7 +1718,7 @@ export const actions = { if (recalPartNumbers && recalPartNumbers.length > 0 && carId) { let additionalQueryParams = ``; for (let i = 0; i < recalPartNumbers.length; i++) { - additionalQueryParams += `&partNumbers[${i}]=4${recalPartNumbers[i]}`; + additionalQueryParams += `&partNumbers[${i}]=${recalPartNumbers[i]}`; } additionalQueryParams += `&carId=${carId}`; endPoint += additionalQueryParams;