mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add etas resolver on shuttle object
This commit is contained in:
@@ -112,6 +112,34 @@ export const resolvers: Resolvers<ServerContext> = {
|
||||
|
||||
return etaForNextStop;
|
||||
},
|
||||
etas: async (parent, args, contextValue, info) => {
|
||||
const etasForShuttle = await contextValue.repository.getEtasForShuttleId(parent.id);
|
||||
if (!etasForShuttle) return null;
|
||||
|
||||
const computedEtas = await Promise.all(etasForShuttle.map(async ({
|
||||
secondsRemaining,
|
||||
stopId,
|
||||
}): Promise<Eta | null> => {
|
||||
const stop = await contextValue.repository.getStopById(stopId);
|
||||
if (stop === null) return null;
|
||||
|
||||
return {
|
||||
secondsRemaining,
|
||||
stop: {
|
||||
coordinates: stop.coordinates,
|
||||
id: stop.id,
|
||||
name: stop.name,
|
||||
},
|
||||
shuttle: parent,
|
||||
}
|
||||
}));
|
||||
|
||||
if (computedEtas.every((eta) => eta !== null)) {
|
||||
return computedEtas;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
},
|
||||
Stop: {
|
||||
orderedStops: async (parent, args, contextValue, info) => {
|
||||
@@ -140,11 +168,11 @@ export const resolvers: Resolvers<ServerContext> = {
|
||||
};
|
||||
}));
|
||||
|
||||
if (!computedOrderedStops.every((value) => value !== null)) {
|
||||
return [];
|
||||
if (computedOrderedStops.every((value) => value !== null)) {
|
||||
return computedOrderedStops as OrderedStop[];
|
||||
}
|
||||
|
||||
return computedOrderedStops as OrderedStop[];
|
||||
return [];
|
||||
}
|
||||
},
|
||||
OrderedStop: {
|
||||
@@ -192,5 +220,5 @@ export const resolvers: Resolvers<ServerContext> = {
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user