From 13dce97cf1c02fe0ae73d41fcd7af7abb5944ab8 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 23 Dec 2024 12:05:34 -0800 Subject: [PATCH] add resolver for shuttle eta --- src/resolvers.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/resolvers.ts b/src/resolvers.ts index 4b8604e..bfdadcf 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -104,13 +104,23 @@ export const resolvers: Resolvers = { } }, Shuttle: { - eta: (parent, args, contextValue, info) => { - const etaForNextStop = parent.etas?.find((eta) => eta.stop.id === args.forStopId); - if (!etaForNextStop) { - return null; - } + eta: async (parent, args, contextValue, info) => { + if (!args.forStopId) return null; + const etaForStopId = await contextValue.repository.getEtaForShuttleAndStopId(parent.id, args.forStopId); + if (etaForStopId === null) return null; - return etaForNextStop; + const stop = await contextValue.repository.getStopById(etaForStopId.stopId); + if (stop === null) return null; + + return { + stop: { + coordinates: stop.coordinates, + id: stop.id, + name: stop.name, + }, + secondsRemaining: etaForStopId.secondsRemaining, + shuttle: parent, + }; }, etas: async (parent, args, contextValue, info) => { const etasForShuttle = await contextValue.repository.getEtasForShuttleId(parent.id);