From 8a93a379499b13f2bdc65f0337d1a13b6f6b3743 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Wed, 30 Aug 2023 15:57:46 -0400 Subject: [PATCH] add servicelocation zipcode to --- src/store/index.js | 146 ++++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 76 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 24014a3c..01d36851 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,3 +1,4 @@ +/* eslint-disable no-use-before-define */ /* eslint-disable max-len */ import { defineStore } from 'pinia'; import { endpoints } from '@/constants/endpoints'; @@ -203,26 +204,33 @@ export const useMainStore = defineStore({ issIsCoverageVerified: state.order.payment.insuranceCoverage.isVerified, issHasRecalibrationPart: getHasRecalibrationPart(state), issSelectedMultiGlass: state.order.damage.glassToReplace?.length > 1, - issSelectedWindshieldGlass: getNonFalseValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, - 'glassLocation').includes(damageLocationsSelected.WINDSHIELD), - issSelectedBackGlass: getNonFalseValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, - 'glassLocation').includes(damageLocationsSelected.REAR), - issSelectedDriverSideGlass: getNonFalseValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, - 'glassLocation').includes(damageLocationsSelected.DRIVER), - issSelectedPassengerSideGlass: getNonFalseValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, - 'glassLocation').includes(damageLocationsSelected.PASSENGER), + issSelectedWindshieldGlass: getNonFalseValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, 'glassLocation') + .includes(damageLocationsSelected.WINDSHIELD), + issSelectedBackGlass: getNonFalseValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, 'glassLocation') + .includes(damageLocationsSelected.REAR), + issSelectedDriverSideGlass: getNonFalseValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, 'glassLocation') + .includes(damageLocationsSelected.DRIVER), + issSelectedPassengerSideGlass: getNonFalseValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, 'glassLocation') + .includes(damageLocationsSelected.PASSENGER), issOrderPartNumbers: [ - ...getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, - 'partNumber'), - ...getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.otherParts, - 'partNumber') + ...getNonFalseValuesOfPropertyInArrayOfObjects( + state.order.lineItems.glassParts, + 'partNumber' + ), + ...getNonFalseValuesOfPropertyInArrayOfObjects( + state.order.lineItems.otherParts, + 'partNumber' + ) ], - issOrderPartTypes: [ - ...getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, - 'recalibrationType'), - ...getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.otherParts, - 'recalibrationType') + ...getNonFalseValuesOfPropertyInArrayOfObjects( + state.order.lineItems.glassParts, + 'recalibrationType' + ), + ...getNonFalseValuesOfPropertyInArrayOfObjects( + state.order.lineItems.otherParts, + 'recalibrationType' + ) ] }), experimentSettings: (state) => state.applicationUser.experiments @@ -599,8 +607,7 @@ export const useMainStore = defineStore({ async getPriceOrderItems(availableLineItems) { let zipCodeToUse = this.order.serviceLocation.zipCode; let ctuToUse = this.order.serviceLocation.zipCodeCtu; - const availableLineItemsFormattedForRequest - = getLineItemQueryStringForPricing(availableLineItems); + const availableLineItemsFormattedForRequest = getLineItemQueryStringForPricing(availableLineItems); const { vehicle } = this.order; // WARNING @@ -608,8 +615,8 @@ export const useMainStore = defineStore({ // and ctu is available. Also, EON may need to be implemented. zipCodeToUse = '44902'; ctuToUse = '01820'; - const queryString - = `ParentAccountNumber=${applicationConfig.CASH_PARENT_ACCOUNT_NUMBER}` + const queryString = + `ParentAccountNumber=${applicationConfig.CASH_PARENT_ACCOUNT_NUMBER}` + `&CTU=${ctuToUse}` + `&CarId=${vehicle.carId}` + `&Make=${vehicle.make}` @@ -637,16 +644,14 @@ export const useMainStore = defineStore({ const lineItemsWithOnlyPartNumbers = this.order.lineItems.glassParts.map((glassPart) => ({ partNumber: glassPart.partNumber })); - const lineItems = buildQueryStringParameterFromArrayOfComplexObjects(lineItemsWithOnlyPartNumbers, - 'lineItems'); + const lineItems = buildQueryStringParameterFromArrayOfComplexObjects(lineItemsWithOnlyPartNumbers, 'lineItems'); const { vehicle } = this.order; const { carId } = vehicle; const { damage } = this.order; const glassArray = convertGlassPieceNamingForApi(damage.glassToReplace); - const glassPieces = buildQueryStringParameterFromArrayOfComplexObjects(glassArray, - 'glassPieces'); + const glassPieces = buildQueryStringParameterFromArrayOfComplexObjects(glassArray, 'glassPieces'); return globalMethods.callHttpClient({ method: endpoints.GetServiceabilityDetails.method, @@ -679,23 +684,16 @@ export const useMainStore = defineStore({ saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, selectedWindshieldChipCount) { const selectedGlassPassedInSorted = selectedGlassToReplace.slice().sort(); - const isGlassToReplaceTheSame - = this.order.damage.glassToReplace?.length === selectedGlassToReplace.length - && this.order.damage.glassToReplace - .slice() - .sort() - .every((obj, index) => obj.glassLocation === selectedGlassPassedInSorted[index].glassLocation + const isGlassToReplaceTheSame = this.order.damage.glassToReplace?.length === selectedGlassToReplace.length + && this.order.damage.glassToReplace + .slice() + .sort() + .every((obj, index) => obj.glassLocation === selectedGlassPassedInSorted[index].glassLocation && obj.glassName === selectedGlassPassedInSorted[index].glassName); - const isWindshieldRepairTheSame - = isWindshieldRepair === this.order.damage.isRepair; - - const isChipCountTheSame - = selectedWindshieldChipCount === this.order.damage.numberOfChips; - - const isDamageChanging - = !isGlassToReplaceTheSame - || !isWindshieldRepairTheSame - || (isWindshieldRepair && !isChipCountTheSame); + const isWindshieldRepairTheSame = isWindshieldRepair === this.order.damage.isRepair; + const isChipCountTheSame = selectedWindshieldChipCount === this.order.damage.numberOfChips; + const isDamageChanging = !isGlassToReplaceTheSame || !isWindshieldRepairTheSame + || (isWindshieldRepair && !isChipCountTheSame); if (isDamageChanging) { // Reset dependent state when changing @@ -927,16 +925,14 @@ export const useMainStore = defineStore({ this.order.customer.address.zipCode = customerQuestions.addressQuestions.zipCode; this.order.customer.firstName = customerQuestions.firstName; this.order.customer.lastName = customerQuestions.lastName; + this.order.serviceLocation.zipCode = customerQuestions.addressQuestions.zipCode; }, savePartQuestionAnswers(partQuestionAnswersArray) { // if part question answers have changed, reset subsequent question answers - const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue(this.order.damage.partQuestionAnswers, - 'result'); - const sortedPartQuestionAnswersArray = sortArrayOfObjectsByPropertyValue(partQuestionAnswersArray, - 'result'); - const havePartQuestionAnswersChanged - = sortedPreviousResultsArray?.length !== sortedPartQuestionAnswersArray.length - || !sortedPreviousResultsArray?.every((x, i) => x.result === sortedPartQuestionAnswersArray[i].result); + const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue(this.order.damage.partQuestionAnswers, 'result'); + const sortedPartQuestionAnswersArray = sortArrayOfObjectsByPropertyValue(partQuestionAnswersArray, 'result'); + const havePartQuestionAnswersChanged = sortedPreviousResultsArray?.length !== sortedPartQuestionAnswersArray.length + || !sortedPreviousResultsArray?.every((x, i) => x.result === sortedPartQuestionAnswersArray[i].result); if (havePartQuestionAnswersChanged) { this.updateGlassParts(null); @@ -954,13 +950,10 @@ export const useMainStore = defineStore({ this.updatePartQuestionAnswers(partQuestionAnswersArray); }, saveMoldingQuestionAnswers(moldingQuestionAnswersArray) { - const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue(this.order.damage.moldingQuestionAnswers, - 'result'); - const sortedMoldingQuestionAnswersArray = sortArrayOfObjectsByPropertyValue(moldingQuestionAnswersArray, - 'result'); - const haveMoldingQuestionAnswersChanged - = sortedPreviousResultsArray?.length !== sortedMoldingQuestionAnswersArray.length - || !sortedPreviousResultsArray?.every((x, i) => x.result === sortedMoldingQuestionAnswersArray[i].result); + const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue(this.order.damage.moldingQuestionAnswers, 'result'); + const sortedMoldingQuestionAnswersArray = sortArrayOfObjectsByPropertyValue(moldingQuestionAnswersArray, 'result'); + const haveMoldingQuestionAnswersChanged = sortedPreviousResultsArray?.length !== sortedMoldingQuestionAnswersArray.length + || !sortedPreviousResultsArray?.every((x, i) => x.result === sortedMoldingQuestionAnswersArray[i].result); if (haveMoldingQuestionAnswersChanged) { this.updateGlassParts(null); @@ -974,13 +967,10 @@ export const useMainStore = defineStore({ }, saveCapabilityQuestionAnswers(capabilityQuestionAnswersArray) { - const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue(this.order.damage.capabilityQuestionAnswers, - 'result'); - const sortedCapabilityQuestionAnswersArray = sortArrayOfObjectsByPropertyValue(capabilityQuestionAnswersArray, - 'result'); - const haveCapabilityQuestionAnswersChanged - = sortedPreviousResultsArray?.length !== sortedCapabilityQuestionAnswersArray.length - || !sortedPreviousResultsArray?.every((x, i) => x.result === sortedCapabilityQuestionAnswersArray[i].result); + const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue(this.order.damage.capabilityQuestionAnswers, 'result'); + const sortedCapabilityQuestionAnswersArray = sortArrayOfObjectsByPropertyValue(capabilityQuestionAnswersArray, 'result'); + const haveCapabilityQuestionAnswersChanged = sortedPreviousResultsArray?.length !== sortedCapabilityQuestionAnswersArray.length + || !sortedPreviousResultsArray?.every((x, i) => x.result === sortedCapabilityQuestionAnswersArray[i].result); if (haveCapabilityQuestionAnswersChanged) { this.updateGlassParts(null); @@ -1064,10 +1054,12 @@ export const useMainStore = defineStore({ endpoint: endpoints.LogPageView.url, payload, logApiCall: false - }).then((response) => response, + }).then( + (response) => response, (error) => { console.log(`Analytics Service Error: ${error.data}`); - }); + } + ); }, logCustomEvent({ userId, sessionKey, pageName, sessionId, category, action, label, value, shouldUseSessionId, experimentsForUser }) { if (pageName == null || pageName.length === 0) { pageName = 'none'; } @@ -1091,10 +1083,12 @@ export const useMainStore = defineStore({ endpoint: endpoints.LogCustomEvent.url, payload, logApiCall: false - }).then((response) => response, + }).then( + (response) => response, (error) => { console.log(`Analytics Service Error: ${error.data}`); - }); + } + ); }, initializeSession({ userId, sessionId, userAgent, referrer }) { const payload = { @@ -1113,10 +1107,12 @@ export const useMainStore = defineStore({ endpoint: endpoints.InitializeSession.url, payload, logApiCall: false - }).then((response) => response, + }).then( + (response) => response, (error) => { console.log(`Analytics Service Error: ${error.data}`); - }); + } + ); }, updateLastPageVisited(lastPageVisited) { @@ -1290,19 +1286,17 @@ export const useMainStore = defineStore({ // Private Functions function getHasRecalibrationPart(state) { - const hasRequiresRecalibration - = getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, - 'requiresRecalibration')?.length > 0; - const hasRecalibrationType - = getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, - 'recalibrationType')?.length > 0; + const hasRequiresRecalibration = getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, 'requiresRecalibration')?.length > 0; + const hasRecalibrationType = getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, 'recalibrationType')?.length > 0; if (hasRequiresRecalibration) { if (hasRecalibrationType) { // Has both 'requiresRecalibration' and 'recalibrationType' and 'recalibrationType' return ( - getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, - 'recalibrationType')[0].toLowerCase() !== 'unknown' + getNonFalseValuesOfPropertyInArrayOfObjects( + state.order.lineItems.glassParts, + 'recalibrationType' + )[0].toLowerCase() !== 'unknown' ); } // Has 'requiresRecalibration' but no 'recalibrationType' at all