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);