Skip to content

Commit

Permalink
Adult limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Kendal committed Feb 6, 2024
1 parent 3186957 commit 20509c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 11 additions & 2 deletions frontend/src/TicketChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/TicketVehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 20509c3

Please sign in to comment.