Skip to content

Commit

Permalink
Changes to endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Neelashab committed Apr 10, 2024
1 parent 6dc80c4 commit 5893fe8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
44 changes: 27 additions & 17 deletions src/controllers/FlightRequest.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,33 @@ export const getAllFlightRequestsForUser = async (
);

// Retrieve flight legs for each flight request and format the data
const formattedFlightRequests = await Promise.all(
trimmedFlightRequests.map(async request => {
const flightLegs = await base('Flight Legs')
.select({
filterByFormula: `{Request AirTable Record ID} = "${request.id}"`,
})
.all();

// Format the flight request data and include the corresponding flight legs
return {
...request,
flightLegs: flightLegs.map(leg =>
trimFlightLeg(leg as unknown as FlightLegData)
),
};
})
);

const promises = trimmedFlightRequests.map(async request => {
return (request['Flight Legs'].map(
async flightLegId =>
await base('Flight Legs')
.select({
filterByFormula: `{AirTable Record ID} = "${flightLegId}"`,
})
.all()
))
}
);

const flightLegs = flightLegsDetails.map(
request => (request as any)._rawJson
);

console.log(flightLegs);

// Format the flight request data and include the corresponding flight legs
return {
...request,
flightLegs: flightLegsDetails.map(leg =>
trimFlightLeg(leg as unknown as FlightLegData)
),
};
});

return res.status(200).json(formattedFlightRequests);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ router.post('/passenger/:id', validateAuth, createPassenger);
router.put('/passenger/:id', validateAuth, updatePassenger);

/* Flight Request Controller Routes */
router.get('/requests/', validateAuth, getAllFlightRequestsForUser);
router.get('/requests', validateAuth, getAllFlightRequestsForUser);
router.get('/requests/:id', validateAuth, getFlightRequestById);
router.get('/requests/:id/legs', validateAuth, getFlightLegsById);
router.post('/requests/', validateAuth, createFlightRequest);
Expand Down

0 comments on commit 5893fe8

Please sign in to comment.