add resolver for previous stop

This commit is contained in:
2024-12-22 19:48:25 -08:00
parent eb6652c290
commit 4d904bab10

View File

@@ -155,6 +155,28 @@ export const resolvers: Resolvers<ServerContext> = {
const nextStopObject = await contextValue.repository.getStopById(nextOrderedStop.stopId); const nextStopObject = await contextValue.repository.getStopById(nextOrderedStop.stopId);
if (!nextStopObject) return null; if (!nextStopObject) return null;
return {
route: parent.route,
stop: {
coordinates: nextStopObject.coordinates as Coordinates,
id: nextStopObject.id,
name: nextStopObject.name,
}
}
},
previousStop: async (parent, args, contextValue, info): Promise<OrderedStop | null> => {
const routeId = parent.route.id;
const stopId = parent.stop.id;
const currentOrderedStop = await contextValue.repository.getOrderedStopByRouteAndStopId(routeId, stopId);
if (!currentOrderedStop) return null;
const previousOrderedStop = currentOrderedStop.previousStop;
if (!previousOrderedStop) return null;
const nextStopObject = await contextValue.repository.getStopById(previousOrderedStop.stopId);
if (!nextStopObject) return null;
return { return {
route: parent.route, route: parent.route,
stop: { stop: {