add resolver for shuttle eta

This commit is contained in:
2024-12-23 12:05:34 -08:00
parent 4f0a10d0c4
commit 13dce97cf1

View File

@@ -104,13 +104,23 @@ export const resolvers: Resolvers<ServerContext> = {
} }
}, },
Shuttle: { Shuttle: {
eta: (parent, args, contextValue, info) => { eta: async (parent, args, contextValue, info) => {
const etaForNextStop = parent.etas?.find((eta) => eta.stop.id === args.forStopId); if (!args.forStopId) return null;
if (!etaForNextStop) { const etaForStopId = await contextValue.repository.getEtaForShuttleAndStopId(parent.id, args.forStopId);
return null; 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) => { etas: async (parent, args, contextValue, info) => {
const etasForShuttle = await contextValue.repository.getEtasForShuttleId(parent.id); const etasForShuttle = await contextValue.repository.getEtasForShuttleId(parent.id);