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; if (!parent.stop) return null; const system = contextValue.findSystemById(parent.stop.systemId); if (!system) return null; const currentOrderedStop = await system.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId); if (!currentOrderedStop) return null; const nextOrderedStop = currentOrderedStop.nextStop; if (!nextOrderedStop) return null; const nextOrderedStopObject = await system.shuttleRepository.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; if (!parent.stop) return null; const system = contextValue.findSystemById(parent.stop.systemId); if (!system) return null; const currentOrderedStop = await system.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId); if (!currentOrderedStop) return null; const previousOrderedStop = currentOrderedStop.previousStop; if (!previousOrderedStop) return null; const previousOrderedStopObject = await system.shuttleRepository.getStopById(previousOrderedStop.stopId); if (!previousOrderedStopObject) return null; return { route: parent.route, routeId: parent.routeId, stopId: previousOrderedStopObject.id, } }, stop: async (parent, args, contextValue, _info) => { if (!parent.stop) return null; const system = contextValue.findSystemById(parent.stop.systemId); if (!system) return null; return await system.shuttleRepository.getStopById(parent.stopId); }, route: async (parent, args, contextValue, _info) => { if (!parent.stop) return null; const system = contextValue.findSystemById(parent.stop.systemId); if (!system) return null; return await system.shuttleRepository.getRouteById(parent.routeId); }, }, }