From 4d904bab1009edb79dd153771ceb8619e467f803 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Sun, 22 Dec 2024 19:48:25 -0800 Subject: [PATCH] add resolver for previous stop --- src/resolvers.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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: {