Updates for getting recal parts as child parts

This commit is contained in:
Bill Richardson 2024-09-30 13:40:12 -04:00
parent 91e7920192
commit 29c7125783
4 changed files with 65 additions and 2 deletions

View file

@ -104,6 +104,19 @@ const endpoints = Object.freeze({
url: `${PARTS_BASE_URL}/rain-defense`,
method: 'GET'
},
GetRecalParts: {
url: (
carId,
partNumber,
recalibrationType,
parentAccountNumber,
zipCode,
applicationName,
referralSequenceNumber
// eslint-disable-next-line max-len
) => `${PARTS_BASE_URL}/recal-parts/${carId}/${partNumber}/${recalibrationType}/${parentAccountNumber}/${zipCode}/${applicationName}/${referralSequenceNumber}`,
method: 'GET'
},
GetSupportingItems: {
url: `${PARTS_BASE_URL}/supporting-items`,
method: 'POST'

View file

@ -159,6 +159,7 @@ export default {
// Call APIs
const cmsContentPromise = fetchCmsContentForPage(to?.query?.issPage);
const supportingItemsPromise = store.getSupportingItems();
const getRecalPartsPromise = store.getRecalParts();
// Settle promises and get results
const promiseResultMap = [
@ -169,6 +170,10 @@ export default {
{
resultKey: 'supportingItems',
promise: supportingItemsPromise
},
{
resultKey: 'recalParts',
promise: getRecalPartsPromise
}
];

View file

@ -414,8 +414,8 @@ export default {
);
if (this.isWindshieldRepair) {
const supportingItems =
await useMainStore().getSupportingItems();
await useMainStore().getRecalParts();
const supportingItems = await useMainStore().getSupportingItems();
useMainStore().updateSupportingItems(supportingItems.data);
}

View file

@ -1020,6 +1020,51 @@ export const useMainStore = defineStore({
}).catch((error) => reject(error));
});
},
async getRecalParts() {
const { glassParts } = this.lineItems;
const { carId } = this.vehicle;
const { parentAccountNumber, referralSequenceNumber } = this.order;
const { zipCode } = this.order.serviceLocation;
if (glassParts && glassParts.length > 0) {
glassParts.forEach((glassPart) => {
if (glassPart.requiresRecalibration) {
const partNumberChecked = glassPart.partNumber;
globalMethods
.callHttpClient({
method: endpoints.GetRecalParts.method,
endpoint: endpoints.GetRecalParts.url(
carId,
partNumberChecked,
glassPart.recalibrationType,
parentAccountNumber,
zipCode,
applicationConfig.APPLICATION_NAME,
referralSequenceNumber
)
})
.then((response) => {
const recalResponse = response.data;
if (recalResponse && recalResponse.recalibrationParts && recalResponse.recalibrationParts.length > 0) {
this.addGlassPartRecalibrationInfo(partNumberChecked, recalResponse.recalibrationParts[0]);
}
});
}
});
}
},
addGlassPartRecalibrationInfo(partNumber, recalPartInformation) {
const glassPart = this.lineItems.glassParts.find((gp) => gp.partNumber === partNumber);
if (glassPart) {
const recalChildPart = glassPart.childParts?.find((cp) => cp.partNumber === recalPartInformation.partNumber);
if (!recalChildPart) {
if (!Array.isArray(glassPart.childParts) || !glassPart.childParts.length) {
glassPart.childParts = [];
}
glassPart.childParts.push(recalPartInformation);
}
}
},
async getSupportingItems() {
const { glassParts } = this.lineItems;
const { carId } = this.vehicle;