From edd1dcc4f8a9d2dcc36826623cafe0d46aaf9d51 Mon Sep 17 00:00:00 2001 From: Josh Dassinger Date: Wed, 16 Oct 2024 11:54:09 -0500 Subject: [PATCH] SSR-1632 Update getServiceabilityDetails for API Changes --- src/helpers/querystring-helper.js | 21 +++++++++++++++++++++ src/store/index.js | 22 +++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/helpers/querystring-helper.js b/src/helpers/querystring-helper.js index b827441a..3572916c 100644 --- a/src/helpers/querystring-helper.js +++ b/src/helpers/querystring-helper.js @@ -43,3 +43,24 @@ export function getTaxLineItemQueryString(lineItems, parameterName) { + `&${parameterName}[${index}].kitPrice=${lineItem.kitPrice}`).join('&'); return queryString.length !== 0 ? `&${queryString}` : ''; } + +export function buildURLSearchParams(data) { + const params = new URLSearchParams(); + Object.entries(data).forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach((arrayValue, index) => { + if (typeof value === 'object') { + Object.entries(arrayValue).forEach(([objectKey, objectValue]) => { + params.append(`${key}[${index}].${objectKey}`, `${objectValue}`); + }); + } else { + params.append(`${key}[${index}]`, `${value}`); + } + }); + } else { + params.append(key, `${value}`); + } + }); + + return params; +} diff --git a/src/store/index.js b/src/store/index.js index d0542ae7..826062f2 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -26,7 +26,7 @@ import bailoutCode from '@/constants/bailoutCode'; import partNumberStrings from '@/constants/part-number-strings'; import { findLineItemIndex, getLineItemsFlattened } from '@/helpers/line-items-helper'; import { - buildQueryStringParameterFromArrayOfComplexObjects, + buildQueryStringParameterFromArrayOfComplexObjects, buildURLSearchParams, getLineItemQueryString, getPartNumbersListForQueryString, getTaxLineItemQueryString @@ -1276,18 +1276,26 @@ export const useMainStore = defineStore({ }, getServiceabilityDetails({ serviceZipCode }) { - const lineItems = getLineItemQueryString(this.order.lineItems.supportingItems, 'lineItems'); - - const { vehicle } = this.order; + const { vehicle, damage, parentAccountNumber, referralSequenceNumber, lineItems } = this.order; const { carId } = vehicle; - const { damage } = this.order; const glassArray = convertGlassPieceNamingForApi(damage.glassToReplace); + const lineItemParts = [...lineItems.glassParts, ...lineItems.supportingItems].map((part) => ({ + partNumber: part.partNumber, + recalibrationType: part.recalibrationType + })); - const glassPieces = buildQueryStringParameterFromArrayOfComplexObjects(glassArray, 'glassPieces'); + const params = buildURLSearchParams({ + parentAccountNumber, + referralSequenceNumber, + zip: serviceZipCode, + carId, + glassPieces: glassArray, + lineItems: lineItemParts + }); return globalMethods.callHttpClient({ method: endpoints.GetServiceabilityDetails.method, - endpoint: `${endpoints.GetServiceabilityDetails.url}?zip=${serviceZipCode}&carId=${carId}${lineItems}&${glassPieces}` + endpoint: `${endpoints.GetServiceabilityDetails.url}?${params.toString()}` }); }, lookupVehicleByVin(vin) {