refactor store method

This commit is contained in:
Katie Kroell 2023-10-17 12:46:52 -04:00
parent 9ce800f74f
commit dac7637bdf

View file

@ -77,7 +77,8 @@ const getDefaultState = () => ({
isITAC: null, isITAC: null,
vehicles: [], vehicles: [],
endorsements: [], endorsements: [],
endorsementQuestionAnswers: null endorsementQuestionAnswers: null,
status: null
}, },
customer: { customer: {
address: { address: {
@ -495,36 +496,66 @@ export const useMainStore = defineStore({
}); });
}); });
}, },
async getFinalDeductible() { getFinalDeductible() {
try { const endorsementAnswersToSend = [];
const endorsementAnswersToSend = []; const endorsementAnswers = this.order.policy.endorsementQuestionAnswers;
if (this.order.policy.endorsementQuestionAnswers[0].selectedAnswer.includes('Yes')) { if (endorsementAnswers && endorsementAnswers[0].selectedAnswer?.includes('Yes')) {
endorsementAnswersToSend.push(this.order.policy.endorsementQuestionAnswers[0].endorsement); endorsementAnswersToSend.push(this.order.policy.endorsementQuestionAnswers[0].endorsement);
} }
const response = await globalMethods.callHttpClient({ return new Promise((resolve, reject) => {
globalMethods.callHttpClient({
method: endpoints.FinalDeductible.method, method: endpoints.FinalDeductible.method,
endpoint: endpoints.FinalDeductible.url, endpoint: endpoints.FinalDeductible.url,
payload: { payload: {
accountNumber: this.issConfig.parentAccountNumber?.toString() ?? '', accountNumber: this.issConfig.parentAccountNumber?.toString() ?? '',
currentDeductible: this.order.currentDeductible, currentDeductible: this.order.currentDeductible,
noCoverage: this.order.policy.noCoverage, noCoverage: this.order.policy.noCoverage,
endorsements: endorsementAnswersToSend, // FIX endorsements: endorsementAnswersToSend,
policy: { policy: {
status: 'Active', 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() { getDuplicateReferrals() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
globalMethods.callHttpClient({ globalMethods.callHttpClient({
@ -991,7 +1022,8 @@ export const useMainStore = defineStore({
noCoverage: policy.noCoverage, noCoverage: policy.noCoverage,
policyLookupSuccessful: policy.policyLookupSuccessful, policyLookupSuccessful: policy.policyLookupSuccessful,
originalDeductible: this.order.originalDeductible, originalDeductible: this.order.originalDeductible,
currentDeductible: this.order.currentDeductible currentDeductible: this.order.currentDeductible,
status: policy.status
}, },
customer: { customer: {
address: { address: {