From 5c86c0546ccc24b8f30597b6affa035271576103 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Tue, 17 Oct 2023 15:56:56 -0400 Subject: [PATCH] refactoring --- src/store/index.js | 51 +++++++++------------------------------------- 1 file changed, 10 insertions(+), 41 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 197875ca..66215e5f 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -77,7 +77,7 @@ const getDefaultState = () => ({ isITAC: null, vehicles: [], endorsements: [], - endorsementQuestionAnswers: null, + endorsementQuestionAnswers: [], status: null }, customer: { @@ -497,11 +497,13 @@ export const useMainStore = defineStore({ }); }, getFinalDeductible() { - const endorsementAnswersToSend = []; + const endorsementAnswersForPayload = []; const endorsementAnswers = this.order.policy.endorsementQuestionAnswers; - if (endorsementAnswers && endorsementAnswers[0].selectedAnswer?.includes('Yes')) { - endorsementAnswersToSend.push(this.order.policy.endorsementQuestionAnswers[0].endorsement); + if (endorsementAnswers && endorsementAnswers[0]?.selectedAnswer?.includes('Yes')) { + endorsementAnswersForPayload.push(this.order.policy.endorsementQuestionAnswers[0].endorsement); + return endorsementAnswersForPayload; } + return new Promise((resolve, reject) => { globalMethods.callHttpClient({ method: endpoints.FinalDeductible.method, @@ -510,52 +512,19 @@ export const useMainStore = defineStore({ accountNumber: this.issConfig.parentAccountNumber?.toString() ?? '', currentDeductible: this.order.currentDeductible, noCoverage: this.order.policy.noCoverage, - endorsements: endorsementAnswersToSend, + endorsements: endorsementAnswersForPayload, policy: { - status: 'Active', - // status: this.order.policy.status, + status: 'Active', // change to this.order.policy.status after changing back end request policyState: this.order.vehicle.registration.state } } }).then((r) => { this.updateDeductible(r.data); return resolve(r); - }).catch((error) => { - this.updateDeductible(this.order.originalDeductible); - return reject(error); - }); + }).catch((error) => reject(error)); }); }, - // getFinalDeductible() { - // try { - // const endorsementAnswersToSend = []; - // if (this.order.policy.endorsementQuestionAnswers[0].selectedAnswer.includes('Yes')) { - // endorsementAnswersToSend.push(this.order.policy.endorsementQuestionAnswers[0].endorsement); - // } - // const response = globalMethods.callHttpClient({ - // method: endpoints.FinalDeductible.method, - // endpoint: endpoints.FinalDeductible.url, - // payload: { - // accountNumber: this.issConfig.parentAccountNumber?.toString() ?? '', - // currentDeductible: this.order.currentDeductible, - // noCoverage: this.order.policy.noCoverage, - // endorsements: endorsementAnswersToSend, - // policy: { - // status: this.order.policy.status, - // policyState: this.order.vehicle.registration.state - // } - // } - // }); - // this.updateDeductible(response.data); - // return response; - // } catch (responseError) { - // return { - // error: { - // status: responseError.status - // } - // }; - // } - // }, + getDuplicateReferrals() { return new Promise((resolve, reject) => { globalMethods.callHttpClient({