From 107cec3d693827572244dd0697bbcb4feb53ff5b Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Thu, 24 Oct 2024 14:34:23 -0400 Subject: [PATCH] Updates to provider call. Reorg'd imports on store index.js Sorted by file name (constants, helpers) Updated serviceability call with application name. --- src/constants/part-type-strings.js | 1 + src/helpers/recal-helper.js | 25 +++++++++++ src/store/index.js | 66 +++++++++++++++++++----------- src/store/store.spec.js | 5 ++- 4 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 src/helpers/recal-helper.js diff --git a/src/constants/part-type-strings.js b/src/constants/part-type-strings.js index 62d5452c..3ae87ce9 100644 --- a/src/constants/part-type-strings.js +++ b/src/constants/part-type-strings.js @@ -1,4 +1,5 @@ const partTypeStrings = Object.freeze({ + ADAS_RECALIBRATION: 'ADAS RECALIBRATION', WINDSHIELD: 'WINDSHIELD', FRONT_WIPER: 'FRONT WIPER', REAR_WIPER: 'REAR WIPER', diff --git a/src/helpers/recal-helper.js b/src/helpers/recal-helper.js new file mode 100644 index 00000000..8d680881 --- /dev/null +++ b/src/helpers/recal-helper.js @@ -0,0 +1,25 @@ +import partTypeStrings from '@/constants/part-type-strings'; + +const recalPartTypes = [partTypeStrings.RECALIBRATION, partTypeStrings.ADAS_RECALIBRATION]; + +export function isRecalPart(part) { + return recalPartTypes.some((type) => type === part.partType); +} + +export function isRecalPartOrHasChildRecalPart(glassPart) { + const isGlassPartRecalPart = isRecalPart(glassPart); + + if (!isGlassPartRecalPart && glassPart.childParts && glassPart.childParts.length > 0) { + return glassPart.childParts.filter((cp) => isRecalPartOrHasChildRecalPart(cp)); + } + + return isGlassPartRecalPart; +} + +export function getTopLevelGlassPartsWithRecal(glassParts) { + if (!glassParts) { + return null; + } + + return glassParts.filter((gp) => isRecalPartOrHasChildRecalPart(gp)); +} diff --git a/src/store/index.js b/src/store/index.js index 3da6ca25..e3381940 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,39 +1,40 @@ /* eslint-disable no-use-before-define */ /* eslint-disable max-len */ import { defineStore } from 'pinia'; +import applicationConfig from '@/constants/application-config'; +import bailoutCode from '@/constants/bailoutCode'; +import bailoutMessage from '@/constants/bailoutMessage'; +import coverageStatuses from '@/constants/coverage-statuses'; +import coverageType from '@/constants/coverage-type'; +import damageLocationsSelected from '@/constants/damage-locations-selected'; import { endpoints } from '@/constants/endpoints'; -// eslint-disable-next-line import/no-cycle -import { getDateForSavedSessionTimeout } from '@/helpers/session-helper'; +import { experimentSettings, experimentTriggers, experimentUniverses } from '@/constants/experiments'; +import partNumberStrings from '@/constants/part-number-strings'; +import partTypeStrings from '@/constants/part-type-strings'; +import { paymentMethods } from '@/constants/payment-method-constants'; +import { AppointmentTypeStrings } from '@/constants/schedule-constants'; +import webStorageConstants from '@/constants/web-storage-constants'; // eslint-disable-next-line import/no-cycle import globalMethods from '@/global-methods'; -import { experimentSettings, experimentTriggers, experimentUniverses } from '@/constants/experiments'; -import applicationConfig from '@/constants/application-config'; -import issPageValues from '@/router/router-constants/issPage-values'; -import damageLocationsSelected from '@/constants/damage-locations-selected'; -import coverageStatuses from '@/constants/coverage-statuses'; -import { AppointmentTypeStrings } from '@/constants/schedule-constants'; +// eslint-disable-next-line import/no-cycle +import { getSessionKeyValue, getUserIdValue, deleteISSCookie } from '@/helpers/cookie-helper'; import { convertDateStringToDate, getDateDifferenceInDays, militaryToTwelveHourTime } from '@/helpers/date-helper'; -import { paymentMethods } from '@/constants/payment-method-constants'; -import webStorageConstants from '@/constants/web-storage-constants'; +import { getExperimentSettingValue } from '@/helpers/experiment-helper'; +import { findLineItemIndex, getLineItemsFlattened } from '@/helpers/line-items-helper'; import { deductibleForSelectedVehicle, endorsementsForSelectedVehicle, noCoverageForSelectedVehicle, repairWaivedForSelectedVehicle } from '@/helpers/policy-vehicle-helper'; -import partTypeStrings from '@/constants/part-type-strings'; -import bailoutMessage from '@/constants/bailoutMessage'; -import bailoutCode from '@/constants/bailoutCode'; -import partNumberStrings from '@/constants/part-number-strings'; -import { findLineItemIndex, getLineItemsFlattened } from '@/helpers/line-items-helper'; import { - buildQueryStringParameterFromArrayOfComplexObjects, buildURLSearchParams, - getLineItemQueryString, + buildURLSearchParams, getPartNumbersListForQueryString, getTaxLineItemQueryString } from '@/helpers/querystring-helper'; -import coverageType from '@/constants/coverage-type'; -import { getExperimentSettingValue, getFeatureTogglesQueryString } from '@/helpers/experiment-helper'; -import { getSessionKeyValue, getUserIdValue, deleteISSCookie } from '@/helpers/cookie-helper'; +import { getTopLevelGlassPartsWithRecal } from '@/helpers/recal-helper'; +// eslint-disable-next-line import/no-cycle +import { getDateForSavedSessionTimeout } from '@/helpers/session-helper'; +import issPageValues from '@/router/router-constants/issPage-values'; const storeId = 'main'; @@ -1000,23 +1001,41 @@ export const useMainStore = defineStore({ }, getProviders(serviceZipCode) { + const { carId } = this.order.vehicle; const damageType = this.damage.isRepair ? 'Repair' : 'Replace'; + const { parentAccountNumber } = this.issConfig; + const partsWithRecal = getTopLevelGlassPartsWithRecal(this.order.lineItems.glassParts); + const windshieldPartWithRecal = partsWithRecal?.length > 0 ? partsWithRecal[0] : null; + const safeliteOnly = true; const shopRadiusInMiles = 100; + let url = `${endpoints.GetProviders.url}/${serviceZipCode}/${damageType}/${shopRadiusInMiles}/${parentAccountNumber}/${safeliteOnly}/${carId}`; + if (windshieldPartWithRecal) { + url += `/${windshieldPartWithRecal.partNumber}`; + } return globalMethods.callHttpClient({ method: endpoints.GetProviders.method, - endpoint: `${endpoints.GetProviders.url}/${serviceZipCode}/${damageType}/${shopRadiusInMiles}` + endpoint: url }); }, getTpaProviders(zipCode, radius) { + const { carId } = this.order.vehicle; const damageType = this.damage.isRepair ? 'Repair' : 'Replace'; const { parentAccountNumber } = this.issConfig; + const partsWithRecal = getTopLevelGlassPartsWithRecal(this.order.lineItems.glassParts); + const windshieldPartWithRecal = partsWithRecal?.length > 0 ? partsWithRecal[0] : null; const safeliteOnly = false; + + let url = `${endpoints.GetProviders.url}/${zipCode}/${damageType}/${radius}/${parentAccountNumber}/${safeliteOnly}/${carId}`; + if (windshieldPartWithRecal) { + url += `/${windshieldPartWithRecal.partNumber}`; + } + return new Promise((resolve, reject) => { globalMethods.callHttpClient({ method: endpoints.GetProviders.method, - endpoint: `${endpoints.GetProviders.url}/${zipCode}/${damageType}/${radius}/${parentAccountNumber}/${safeliteOnly}` + endpoint: url }).then((response) => resolve(response), (error) => reject(error)); }); }, @@ -1287,6 +1306,7 @@ export const useMainStore = defineStore({ })); const params = buildURLSearchParams({ + applicationName: applicationConfig.APPLICATION_NAME, parentAccountNumber, referralSequenceNumber, zip: serviceZipCode, @@ -1480,7 +1500,7 @@ export const useMainStore = defineStore({ referralSequenceNumber: this.order.referralSequenceNumber, eon: this.order.eon, submitToMainframe: !!this.order.referralNumber, - createWorkOrderNumberForPIA: createWorkOrderNumberForPIA, + createWorkOrderNumberForPIA, lockToken: this.order.lockToken, loadedFromDupeCheck, submitAfterSave: !!submitAfterSave diff --git a/src/store/store.spec.js b/src/store/store.spec.js index c09a877c..8e61ce2d 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1937,9 +1937,11 @@ describe('Store', () => { // Arrange globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); + const carId = getRandomString(10, 14); const parentAccountNumber = getRandomString(6, 6); store.issConfig.parentAccountNumber = parentAccountNumber; store.order.damage.isRepair = isRepair; + store.order.vehicle.carId = carId; const zipCode = getRandomString(6, 6); const radius = getRandomInt(5, 100); const expectedEndpoint = [ @@ -1948,7 +1950,8 @@ describe('Store', () => { damageType, radius, parentAccountNumber, - 'false' + 'false', + carId ].join('/'); // Act