From ce6454fa1f7474bfe56537eeebb6effd0d41771c Mon Sep 17 00:00:00 2001 From: charlotteconze <85513920+charlotteconze@users.noreply.github.com> Date: Sun, 24 Mar 2024 14:00:38 -0500 Subject: [PATCH] Update Passenger.controller.ts --- src/controllers/Passenger.controller.ts | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/controllers/Passenger.controller.ts b/src/controllers/Passenger.controller.ts index 6bf5ce5..bb54c62 100644 --- a/src/controllers/Passenger.controller.ts +++ b/src/controllers/Passenger.controller.ts @@ -42,21 +42,25 @@ export const getAllPassengersForUser = async (req: Request, res: Response) => { return; } else { // get related passengers information - const accompPassengers = [] as Record
[]; - const accompanyingPassengersPromise = record._rawJson.fields[ - 'Related Accompanying Passenger(s)' - ].map(async (id: string) => { - // map through the related passengers and get the passenger information for each one - const passenger = await base('Passengers').find(id.toString()); - accompPassengers.push(passenger); - }); + const accompPassengersPromise = [] as Promise>[]; + + record._rawJson.fields['Related Accompanying Passenger(s)']?.map( + async (id: string) => { + // map through the related passengers and get the passenger information for each one + const passenger = base('Passengers').find(id.toString()); + accompPassengersPromise.push(passenger); + } + ); // Remove any unnecessary data from the passengers - await Promise.all(accompanyingPassengersPromise); - const trimmedPassengers = accompPassengers.map( - (passenger: Record
) => + const passengers = await Promise.all(accompPassengersPromise); + + console.log('HEERE', passengers); + + const trimmedPassengers = + passengers?.map((passenger: Record
) => trimPassenger(passenger._rawJson as unknown as PassengerData) - ); + ) || []; // return the passengers for the user return res.send(trimmedPassengers);