diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index f6ac757a..5c25364c 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -104,6 +104,19 @@ const endpoints = Object.freeze({ url: `${PARTS_BASE_URL}/rain-defense`, method: 'GET' }, + GetRecalParts: { + url: ( + carId, + partNumber, + recalibrationType, + parentAccountNumber, + zipCode, + applicationName, + referralSequenceNumber + // eslint-disable-next-line max-len + ) => `${PARTS_BASE_URL}/recal-parts/${carId}/${partNumber}/${recalibrationType}/${parentAccountNumber}/${zipCode}/${applicationName}/${referralSequenceNumber}`, + method: 'GET' + }, GetSupportingItems: { url: `${PARTS_BASE_URL}/supporting-items`, method: 'POST' diff --git a/src/layouts/coverage-statement/coverage-statement.vue b/src/layouts/coverage-statement/coverage-statement.vue index 136198a2..2b90a4e8 100644 --- a/src/layouts/coverage-statement/coverage-statement.vue +++ b/src/layouts/coverage-statement/coverage-statement.vue @@ -159,6 +159,7 @@ export default { // Call APIs const cmsContentPromise = fetchCmsContentForPage(to?.query?.issPage); const supportingItemsPromise = store.getSupportingItems(); + const getRecalPartsPromise = store.getRecalParts(); // Settle promises and get results const promiseResultMap = [ @@ -169,6 +170,10 @@ export default { { resultKey: 'supportingItems', promise: supportingItemsPromise + }, + { + resultKey: 'recalParts', + promise: getRecalPartsPromise } ]; diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index de8250ed..1561a3bd 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -414,8 +414,8 @@ export default { ); if (this.isWindshieldRepair) { - const supportingItems = - await useMainStore().getSupportingItems(); + const results = await Promise.allSettled([useMainStore().getSupportingItems(), useMainStore().getRecalParts()]); + const supportingItems = results[0]; useMainStore().updateSupportingItems(supportingItems.data); } diff --git a/src/store/index.js b/src/store/index.js index 312912d9..78321758 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1020,11 +1020,60 @@ export const useMainStore = defineStore({ }).catch((error) => reject(error)); }); }, + async getRecalParts() { + const { glassParts } = this.lineItems; + const { carId } = this.vehicle; + const { parentAccountNumber, referralSequenceNumber } = this.order; + const { zipCode } = this.order.serviceLocation; + + if (glassParts && glassParts.length > 0) { + const recalPromises = []; + glassParts.forEach((glassPart) => { + if (glassPart.requiresRecalibration) { + const partNumberChecked = glassPart.partNumber; + recalPromises.push(globalMethods + .callHttpClient({ + method: endpoints.GetRecalParts.method, + endpoint: endpoints.GetRecalParts.url( + carId, + partNumberChecked, + glassPart.recalibrationType, + parentAccountNumber, + zipCode, + applicationConfig.APPLICATION_NAME, + referralSequenceNumber + ) + }) + .then((response) => { + const recalResponse = response.data; + if (recalResponse && recalResponse.recalibrationParts && recalResponse.recalibrationParts.length > 0) { + this.addGlassPartRecalibrationInfo(partNumberChecked, recalResponse.recalibrationParts[0]); + } + })); + } + }); + await Promise.allSettled(recalPromises); + } + }, + addGlassPartRecalibrationInfo(partNumber, recalPartInformation) { + const glassPart = this.lineItems.glassParts.find((gp) => gp.partNumber === partNumber); + if (glassPart) { + const recalChildPart = glassPart.childParts?.find((cp) => cp.partNumber === recalPartInformation.partNumber); + if (!recalChildPart) { + if (!Array.isArray(glassPart.childParts) || !glassPart.childParts.length) { + glassPart.childParts = []; + } + glassPart.childParts.push(recalPartInformation); + } + } + }, async getSupportingItems() { const { glassParts } = this.lineItems; const { carId } = this.vehicle; const { isRepair, numberOfChips } = this.damage; + console.log('supporting http response..'); + return globalMethods .callHttpClient({ method: endpoints.GetSupportingItems.method, @@ -1212,7 +1261,7 @@ export const useMainStore = defineStore({ facilityType: 'Mobile', parentAccountNumber: this.order.parentAccountNumber, billToAccountNumber: this.billToAccountNumber, - isItacOptimized: false, //TODO: Implement with response from getITACPriceOrderItems + isItacOptimized: false, // TODO: Implement with response from getITACPriceOrderItems providerNumber: this.providerNumber, carId: vehicle.carId, coverageStatus: coverageStatuses.mapToApi(insuranceCoverage.coverageStatus),