diff --git a/src/resolvers.ts b/src/resolvers.ts index c84dd6f..91aea32 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -155,6 +155,28 @@ export const resolvers: Resolvers = { const nextStopObject = await contextValue.repository.getStopById(nextOrderedStop.stopId); 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 => { + 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 { route: parent.route, stop: {