Updates to provider call.

Reorg'd imports on store index.js
Sorted by file name (constants, helpers)
Updated serviceability call with application name.
This commit is contained in:
Bill Richardson 2024-10-24 14:34:23 -04:00
parent 40275db79f
commit 107cec3d69
4 changed files with 73 additions and 24 deletions

View file

@ -1,4 +1,5 @@
const partTypeStrings = Object.freeze({
ADAS_RECALIBRATION: 'ADAS RECALIBRATION',
WINDSHIELD: 'WINDSHIELD',
FRONT_WIPER: 'FRONT WIPER',
REAR_WIPER: 'REAR WIPER',

View file

@ -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));
}

View file

@ -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

View file

@ -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