From 20509c37c9bbacf39df378fd583d13d6b13fe221 Mon Sep 17 00:00:00 2001 From: Geoff Kendal Date: Tue, 6 Feb 2024 15:50:40 +0000 Subject: [PATCH] Adult limitations --- frontend/src/TicketChild.js | 13 +++++++++++-- frontend/src/TicketVehicle.js | 8 ++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/frontend/src/TicketChild.js b/frontend/src/TicketChild.js index 7c11db8..d2fe3f1 100644 --- a/frontend/src/TicketChild.js +++ b/frontend/src/TicketChild.js @@ -59,8 +59,17 @@ const TicketChild = ({ groupCode }) => { if (response.ok) { const responseData = await response.json(); - const adultData = responseData.adult || []; - setParentData(adultData); + + const childData = responseData.child || []; + const parentIdsInChild = childData.map(child => child.parent_id); + + // Filter out adults based on the number of matches + const filteredParentData = (responseData.adult || []).filter(adult => { + const matchingChildCount = parentIdsInChild.filter(parentId => parentId === adult.ticket_id).length; + return matchingChildCount <= 1; // Include if 0 or 1 match + }); + + setParentData(filteredParentData); } else { console.error('Error fetching parent data:', response.statusText); } diff --git a/frontend/src/TicketVehicle.js b/frontend/src/TicketVehicle.js index 78274fb..b1cdfbc 100644 --- a/frontend/src/TicketVehicle.js +++ b/frontend/src/TicketVehicle.js @@ -57,8 +57,12 @@ const TicketVehicle = ({ groupCode }) => { if (response.ok) { const responseData = await response.json(); - const adultData = responseData.adult || []; - setDriverData(adultData); + const vehicleData = responseData.vehicle || []; + const driverIdsInVehicles = vehicleData.map(vehicle => vehicle.driver_id); + const filteredAdultData = (responseData.adult || []).filter(adult => { + return !driverIdsInVehicles.includes(adult.ticket_id); + }); + setDriverData(filteredAdultData); } else { console.error('Error fetching driver data:', response.statusText); }