Match selected parts to API parts
This commit is contained in:
parent
0ab3396502
commit
62fbdd916b
1 changed files with 34 additions and 2 deletions
|
|
@ -154,8 +154,40 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
forwardButtonAction() {
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue