From 5a6d72243b2850d623f207ad2674655547587904 Mon Sep 17 00:00:00 2001 From: David Ly Date: Mon, 9 Dec 2024 13:06:25 +0100 Subject: [PATCH] Fixed createdOneDamage by filtering parts by inspectionId --- packages/common/src/state/actions/createdOneDamage.ts | 9 +++++++-- .../common/test/state/actions/createdOneDamage.test.ts | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/common/src/state/actions/createdOneDamage.ts b/packages/common/src/state/actions/createdOneDamage.ts index 20c42cd03..9a3c8f751 100644 --- a/packages/common/src/state/actions/createdOneDamage.ts +++ b/packages/common/src/state/actions/createdOneDamage.ts @@ -57,8 +57,13 @@ export function createdOneDamage(state: MonkState, action: MonkCreatedOneDamageA const newDamages = damages.filter( (damage) => ![payload.damage.id, payload.localId].includes(damage.id), ); - const partsRelated = action.payload.damage.parts - .map((part) => parts.find((value) => value.type === part)?.id) + const partsRelated = payload.damage.parts + .map( + (part) => + parts + .filter((value) => value.inspectionId === payload.damage.inspectionId) + .find((value) => value.type === part)?.id, + ) .filter((v) => v !== undefined) as string[]; const newParts = parts.map((part) => { if (partsRelated.includes(part.id)) { diff --git a/packages/common/test/state/actions/createdOneDamage.test.ts b/packages/common/test/state/actions/createdOneDamage.test.ts index 8a2bbbdc0..a0eca9bee 100644 --- a/packages/common/test/state/actions/createdOneDamage.test.ts +++ b/packages/common/test/state/actions/createdOneDamage.test.ts @@ -44,6 +44,7 @@ describe('CreatedOneDamage action handlers', () => { id: 'part-id', type: VehiclePart.ROOF, damages: [] as string[], + inspectionId: 'inspections-test', }; state.inspections.push({ id: 'inspections-test',