From e54ead578e532059944a1632ff85bc58cb4f4c22 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Thu, 5 Sep 2024 17:02:15 -0400 Subject: [PATCH] Add call to recal endpoint --- src/constants/endpoints.js | 4 +++ src/constants/store-actions.js | 1 + src/mixins/vehicle-questions-mixin.js | 12 +++++++- src/store/index.js | 40 +++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 43abf149c..2b5c654e5 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -84,6 +84,10 @@ const endpoints = { url: "/parts/api/v1/parts/supporting-items", method: "POST", }, + GetRecalPart: { + url: "/parts/api/v1/parts/recal-parts", + method: "GET", + }, GetAlertReasons: { url: "/location/api/v1/location/alert-reasons", method: "GET", diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 069079d35..f5c7ea047 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -53,6 +53,7 @@ const storeActions = { VALIDATE_ORDER_PROMO_AND_SAVE_SERVER_DATA: "validateOrderPromoAndSaveServerData", REVALIDATE_ORDER_PROMOS_AND_SAVE_SERVER_DATA: "revalidateOrderPromosAndSaveServerData", GET_INSURANCE_COMPANY_LIST: "getInsuranceCompanyList", + GET_RECAL_PARTS_AND_SAVE_TO_LINE_ITEMS: "getRecalPartsAndSaveToLineItems", // DEPENDENCY MUTATIONS RESET_DAMAGE_STATE_AND_DEPENDENCIES: "resetDamageAndDependencies", diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index 2749d1933..517fc7c90 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -450,7 +450,17 @@ export default { const collectedGlassParts = this.reducedGlassPartsArray(partsOrQuestions); // save to store lineItems.glassParts - self.dispatchStoreAction(storeActions.SAVE_GLASS_PARTS, collectedGlassParts, false); + await self.dispatchStoreAction( + storeActions.SAVE_GLASS_PARTS, + collectedGlassParts, + false + ); + + await self.dispatchStoreActionWithLogging( + storeActions.GET_RECAL_PARTS_AND_SAVE_TO_LINE_ITEMS, + null, + currentPage + ); const payment = store.getters.payment; diff --git a/src/store/index.js b/src/store/index.js index aa5747a0f..a74a52623 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2855,6 +2855,46 @@ export const actions = { externalParameterMMS.externalParameterStyle ); }, + + async getRecalPartsAndSaveToLineItems(context, { pageNameToLog }) { + // identify each part that needs recal + const glassParts = context.state.order?.lineItems?.glassParts ?? []; + + for (let i = 0; i < glassParts.length; i++) { + // does this part need recal? + const needsRecal = + !!glassParts[i].requiresRecalibration && !!glassParts[i].recalibrationType; + + if (needsRecal) { + const recalType = glassParts[i].recalibrationType; + const parentAccountNumber = + context.state.order.payment.parentAccountNumber ?? + applicationConfig.CASH_PARENT_ACCOUNT_NUMBER; + + // Get part from API + const urlExtension = `${context.state.order.vehicle.carId}/${glassParts[i].partNumber}/${recalType}/${parentAccountNumber}/${context.state.order.serviceLocation.zipCode}/${applicationConfig.ANALYTICS_APPLICATION_NAME}/${context.state.order.referralSequenceNumber}`; + + const recalPartResponse = await globalMethods.callHttpClient({ + method: endpoints.GetRecalPart.method, + endpoint: `${endpoints.GetRecalPart.url}/${urlExtension}`, + payload: {}, + pageNameToLog: pageNameToLog, + }); + + // If any parts retrieved, add as children to the glass part. + if ( + recalPartResponse.status === 200 && + recalPartResponse.data.recalibrationParts?.length > 0 + ) { + if (!glassParts[i].childParts) { + glassParts[i].childParts = []; + } + + glassParts[i].childParts.push(...recalPartResponse.data.recalibrationParts); + } + } + } + }, }; export default createStore({