import { OrderedStop, Resolvers } from "../generated/graphql"; import { ServerContext } from "../ServerContext"; export const OrderedStopResolvers: Resolvers = { OrderedStop: { nextStop: async (parent, args, contextValue, info): Promise => { const routeId = parent.routeId; const stopId = parent.stopId; const currentOrderedStop = await contextValue.repository.getOrderedStopByRouteAndStopId(routeId, stopId); if (!currentOrderedStop) return null; const nextOrderedStop = currentOrderedStop.nextStop; if (!nextOrderedStop) return null; const nextOrderedStopObject = await contextValue.repository.getStopById(nextOrderedStop.stopId); if (!nextOrderedStopObject) return null; return { route: parent.route, routeId: parent.routeId, stopId: nextOrderedStopObject.id, } }, previousStop: async (parent, args, contextValue, info): Promise => { const routeId = parent.routeId; const stopId = parent.stopId; const currentOrderedStop = await contextValue.repository.getOrderedStopByRouteAndStopId(routeId, stopId); if (!currentOrderedStop) return null; const previousOrderedStop = currentOrderedStop.previousStop; if (!previousOrderedStop) return null; const previousOrderedStopObject = await contextValue.repository.getStopById(previousOrderedStop.stopId); if (!previousOrderedStopObject) return null; return { route: parent.route, routeId: parent.routeId, stopId: previousOrderedStopObject.id, } }, stop: async (parent, args, contextValue, info) => { return await contextValue.repository.getStopById(parent.stopId); }, route: async (parent, args, contextValue, info) => { return await contextValue.repository.getRouteById(parent.routeId); }, }, }