From f262b05df168f41dd050a78e1f30c365ca8ec9e4 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Mon, 20 Apr 2026 10:44:22 -0400 Subject: [PATCH] refactor method, reuse existing array for answers --- src/helpers/policy-vehicle-helper.js | 27 ++++++++++----------------- src/store/index.js | 9 +-------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/helpers/policy-vehicle-helper.js b/src/helpers/policy-vehicle-helper.js index fbd450d6..783f210d 100644 --- a/src/helpers/policy-vehicle-helper.js +++ b/src/helpers/policy-vehicle-helper.js @@ -20,25 +20,18 @@ export function endorsementsForSelectedVehicle(vehicle) { return []; } export function endorsementCodesForSelectedVehicle(vehicle) { - if (vehicle?.endorsements?.length === 1) { - switch (true) { - case vehicle.endorsements.includes(endorsementOptions.EDUCATOR): - return endorsementCodes_LibertyMutual.EDUCATOR; - case vehicle.endorsements.includes(endorsementOptions.PARKING_GUARD): - return endorsementCodes_LibertyMutual.PARKING_GUARD; - } + if (!Array.isArray(vehicle?.endorsements) || vehicle.endorsements.length === 0) { + return ''; } - else if (vehicle?.endorsements?.length > 1) { - let codes = []; - if (vehicle.endorsements.includes(endorsementOptions.EDUCATOR)) { - codes.push(endorsementCodes_LibertyMutual.EDUCATOR); - } - if (vehicle.endorsements.includes(endorsementOptions.PARKING_GUARD)) { - codes.push(endorsementCodes_LibertyMutual.PARKING_GUARD); - } - return codes.join(','); + + let codes = []; + if (vehicle.endorsements.includes(endorsementOptions.EDUCATOR)) { + codes.push(endorsementCodes_LibertyMutual.EDUCATOR); } - return ""; + if (vehicle.endorsements.includes(endorsementOptions.PARKING_GUARD)) { + codes.push(endorsementCodes_LibertyMutual.PARKING_GUARD); + } + return codes.join(','); } export function repairWaivedForSelectedVehicle(vehicle) { return vehicle?.endorsements?.includes(endorsementOptions.REPAIR_WAIVED) ?? false; diff --git a/src/store/index.js b/src/store/index.js index e32e212f..b021aa53 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -111,8 +111,6 @@ export const getDefaultState = () => ({ endorsements: [], endorsementQuestionAnswers: [], cvrgEndorsementCode: null, - educatorEndorsementAnswer: null, - parkingGuardEndorsementAnswer: null, status: null, policyData: null }, @@ -1475,8 +1473,7 @@ export const useMainStore = defineStore({ noCoverage: this.isNoComp, isItac: this.isITAC, cvrgEndorsementCode: policy.cvrgEndorsementCode ?? endorsementCodesForSelectedVehicle(vehicle), - educatorEndorsement: policy.educatorEndorsementAnswer, - parkingGuardEndorsement: policy.parkingGuardEndorsementAnswer + endorsementQuestionAnswers: policy.endorsementQuestionAnswers }, customer: { address: { @@ -2121,8 +2118,6 @@ export const useMainStore = defineStore({ this.order.policy.endorsements = []; this.order.policy.endorsementQuestionAnswers = []; this.order.policy.cvrgEndorsementCode = null; - this.order.policy.educatorEndorsementAnswer = null; - this.order.policy.parkingGuardEndorsementAnswer = null; this.order.policy.policyData = null; this.order.policy.deductible.repair = null; this.order.policy.deductible.replace = null; @@ -2306,8 +2301,6 @@ export const useMainStore = defineStore({ if (answersArray !== null) { const educatorEndorsement = answersArray.find((endorsement) => endorsement.endorsementName === endorsementOptions.EDUCATOR); const parkingGuardEndorsement = answersArray.find((endorsement) => endorsement.endorsementName === endorsementOptions.PARKING_GUARD); - this.order.policy.educatorEndorsementAnswer = educatorEndorsement ? educatorEndorsement.selectedAnswer : null; - this.order.policy.parkingGuardEndorsementAnswer = parkingGuardEndorsement ? parkingGuardEndorsement.selectedAnswer : null; } },