diff --git a/src/store/index.js b/src/store/index.js index b8d29dfc..197875ca 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -77,7 +77,8 @@ const getDefaultState = () => ({ isITAC: null, vehicles: [], endorsements: [], - endorsementQuestionAnswers: null + endorsementQuestionAnswers: null, + status: null }, customer: { address: { @@ -495,36 +496,66 @@ export const useMainStore = defineStore({ }); }); }, - async getFinalDeductible() { - try { - const endorsementAnswersToSend = []; - if (this.order.policy.endorsementQuestionAnswers[0].selectedAnswer.includes('Yes')) { - endorsementAnswersToSend.push(this.order.policy.endorsementQuestionAnswers[0].endorsement); - } - const response = await globalMethods.callHttpClient({ + getFinalDeductible() { + const endorsementAnswersToSend = []; + const endorsementAnswers = this.order.policy.endorsementQuestionAnswers; + if (endorsementAnswers && endorsementAnswers[0].selectedAnswer?.includes('Yes')) { + endorsementAnswersToSend.push(this.order.policy.endorsementQuestionAnswers[0].endorsement); + } + return new Promise((resolve, reject) => { + 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, // FIX + endorsements: endorsementAnswersToSend, policy: { status: 'Active', - policyState: this.order.vehicle.registration.state // check on this + // status: this.order.policy.status, + 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); }); - this.updateDeductible(response.data); - return response; - } catch (responseError) { - return { - error: { - status: responseError.status - } - }; - } + }); }, + // 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({ @@ -991,7 +1022,8 @@ export const useMainStore = defineStore({ noCoverage: policy.noCoverage, policyLookupSuccessful: policy.policyLookupSuccessful, originalDeductible: this.order.originalDeductible, - currentDeductible: this.order.currentDeductible + currentDeductible: this.order.currentDeductible, + status: policy.status }, customer: { address: {