Merge pull request #107 from Safelite/add-isGlassAvailableForCarId
Add isGlassAvailableForCarId method
This commit is contained in:
commit
dea1184316
1 changed files with 35 additions and 28 deletions
|
|
@ -35,6 +35,41 @@ export function getDamageString() {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasMatchingReplacementOption(vehicleDamageOptions, selectedGlassToReplace) {
|
||||||
|
let result = true;
|
||||||
|
const optionsMap = {
|
||||||
|
Windshield: 'windshieldOptions',
|
||||||
|
Driver: 'driverSideOptions',
|
||||||
|
Passenger: 'passengerSideOptions',
|
||||||
|
Rear: 'backGlassOptions',
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const glassToReplace of selectedGlassToReplace) {
|
||||||
|
const propName = optionsMap[glassToReplace.glassLocation];
|
||||||
|
const { availableReplacementOptions } = vehicleDamageOptions[propName];
|
||||||
|
|
||||||
|
if (!availableReplacementOptions.includes(glassToReplace.glassName)) {
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function isGlassAvailableForCarId(carId) {
|
||||||
|
const mainStore = useMainStore();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const vehicleDamageOptionsResponse = await mainStore.getDamageOptions(carId);
|
||||||
|
const selectedGlassToReplace = mainStore.damage.glassToReplace;
|
||||||
|
|
||||||
|
return hasMatchingReplacementOption(vehicleDamageOptionsResponse.data, selectedGlassToReplace);
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commented code are copied directly from DigitalConsumer.FixMyGlass
|
* Commented code are copied directly from DigitalConsumer.FixMyGlass
|
||||||
* and have not been adjusted for ISS.
|
* and have not been adjusted for ISS.
|
||||||
|
|
@ -54,31 +89,3 @@ export function getDamageString() {
|
||||||
// : "glass";
|
// : "glass";
|
||||||
// return returnString;
|
// return returnString;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// export async function isGlassAvailableForCarId(carId) {
|
|
||||||
// const newGlassOptions = await baseMixin.methods.dispatchStoreAction(
|
|
||||||
// storeActions.GET_DAMAGE_OPTIONS,
|
|
||||||
// { carId: carId }
|
|
||||||
// );
|
|
||||||
|
|
||||||
// const currentGlassOptions = store.getters.damage.glassToReplace;
|
|
||||||
|
|
||||||
// const optionsMap = {
|
|
||||||
// Windshield: "windshieldOptions",
|
|
||||||
// Driver: "driverSideOptions",
|
|
||||||
// Passenger: "passengerSideOptions",
|
|
||||||
// Rear: "backGlassOptions",
|
|
||||||
// };
|
|
||||||
|
|
||||||
// for (const option of currentGlassOptions) {
|
|
||||||
// if (
|
|
||||||
// !newGlassOptions.data[
|
|
||||||
// optionsMap[option.glassLocation]
|
|
||||||
// ].availableReplacementOptions.includes(option.glassName)
|
|
||||||
// ) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue