mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-16 23:40:32 +00:00
add resolver for shuttle eta
This commit is contained in:
@@ -104,13 +104,23 @@ export const resolvers: Resolvers<ServerContext> = {
|
||||
}
|
||||
},
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user