mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add resolver for shuttle eta
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user