Create helper files
This commit is contained in:
parent
e54ead578e
commit
6f3e35388b
2 changed files with 40 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ const partTypeStrings = {
|
|||
FRONT_WIPER: "FRONT WIPER",
|
||||
REAR_WIPER: "REAR WIPER",
|
||||
RAIN_DEFENSE: "RAIN DEFENSE",
|
||||
ADAS_RECALIBRATION: "ADAS RECALIBRATION",
|
||||
RECALIBRATION: "RECALIBRATION",
|
||||
REPLACE_FEE: "REPLACE FEE",
|
||||
RECYCLE_FEE: "RECYCLE FEE",
|
||||
|
|
|
|||
39
src/helpers/recal-helper.js
Normal file
39
src/helpers/recal-helper.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { deepClone } from "@/helpers/object-helper";
|
||||
import { partTypeStrings } from "@/constants/part-type-strings";
|
||||
|
||||
const recalPartTypes = [partTypeStrings.RECALIBRATION, partTypeStrings.ADAS_RECALIBRATION];
|
||||
|
||||
export function isRecalPartOrHasChildRecalPart(lineItem) {
|
||||
if (lineItem.childParts && lineItem.childParts.length > 0) {
|
||||
return isRecalPart(lineItem) || containsRecalParts(lineItem.childParts);
|
||||
} else {
|
||||
return isRecalPart(lineItem);
|
||||
}
|
||||
}
|
||||
|
||||
export function isRecalPart(lineItem) {
|
||||
return recalPartTypes.some((type) => lineItem.partType === type);
|
||||
}
|
||||
|
||||
export function containsRecalParts(lineItems) {
|
||||
if (!lineItems) {
|
||||
return false;
|
||||
}
|
||||
return lineItems.some((li) => isRecalPartOrHasChildRecalPart(li));
|
||||
}
|
||||
|
||||
export function getItemsWithoutRecalParts(lineItems) {
|
||||
const copy = deepClone(lineItems);
|
||||
|
||||
const firstLevelFiltered = copy.filter((li) => !isRecalPart(li));
|
||||
|
||||
const childrenFiltered = firstLevelFiltered.map((li) => {
|
||||
if (li.childParts && li.childParts.length > 0) {
|
||||
li.childParts = getItemsWithoutRecalParts(li.childParts);
|
||||
}
|
||||
|
||||
return li;
|
||||
});
|
||||
|
||||
return childrenFiltered;
|
||||
}
|
||||
Loading…
Reference in a new issue