Match selected parts to API parts

This commit is contained in:
FrankRua 2022-02-27 14:56:05 -05:00
parent 0ab3396502
commit 62fbdd916b

View file

@ -154,8 +154,40 @@ export default {
},
forwardButtonAction() {
const p = this.PartsFromApi;
const pickedParts = '';
// Temporary solution to prevent the user from going forward if they have not selected anything.
// will be replaced by validation in the future.
if(Object.keys(this.glassParts).length === 0) {
throw new Error("No parts selected");
}
const selectedGlassPartNumbers = [];
const matchedParts = [];
// Compile all selected parts from the page.
for (let [key, value] of Object.entries(this.glassParts)) {
for (let [glassKey, glassValue] of Object.entries(value)) {
selectedGlassPartNumbers.push(glassValue[0]);
}
}
// Match them to the parts from the API.
for (let [key, value] of Object.entries(this.PartsFromApi.partsOrQuestions)) {
for (let [partKey, partValue] of Object.entries(value.parts)) {
const currentPart = this.PartsFromApi.partsOrQuestions[key].parts[partKey];
const isMatched = selectedGlassPartNumbers.some(p => p === currentPart.partNumber);
if (isMatched) {
matchedParts.push(currentPart);
}
}
}
// If no parts could be matched, throw an error.
if(matchedParts.length === 0) {
throw new Error("Could not match any parts to the selected parts");
}
}
},