import { Coordinates, Resolvers } from "../generated/graphql"; import { ServerContext } from "../ServerContext"; export const SystemResolvers: Resolvers = { System: { routes: async (parent, _args, contextValue, _info) => { const system = contextValue.findSystemById(parent.id); if (!system) { return []; } return await system.shuttleRepository.getRoutes(); }, stops: async (parent, _args, contextValue, _info) => { const system = contextValue.findSystemById(parent.id); if (!system) { return []; } return await system.shuttleRepository.getStops(); }, stop: async (parent, args, contextValue, _info) => { if (!args.id) return null; const system = contextValue.findSystemById(parent.id); if (!system) { return null; } const stop = await system.shuttleRepository.getStopById(args.id); if (stop === null) return null; if (stop.systemId !== parent.id) return null; return { id: stop.id, name: stop.name, coordinates: stop.coordinates as Coordinates, systemId: parent.id, }; }, route: async (parent, args, contextValue, _info) => { if (!args.id) return null; const system = contextValue.findSystemById(parent.id); if (!system) { return null; } const route = await system.shuttleRepository.getRouteById(args.id); if (route === null) return null; if (route.systemId !== parent.id) return null; return { color: route.color, id: route.id, name: route.name, polylineCoordinates: route.polylineCoordinates as Coordinates[], systemId: parent.id, }; }, shuttle: async (parent, args, contextValue, _info) => { if (!args.id) return null; const system = contextValue.findSystemById(parent.id); if (!system) { return null; } const shuttle = await system.shuttleRepository.getShuttleById(args.id); if (shuttle === null) return null; if (shuttle.systemId !== parent.id) return null; return shuttle; }, shuttles: async (parent, _args, contextValue, _info) => { const system = contextValue.findSystemById(parent.id); if (!system) { return []; } return await system.shuttleRepository.getShuttles(); }, parkingSystem: async (parent, _args, contextValue, _info) => { const system = contextValue.findSystemById(parent.id); if (!system) { return null; } if (!system.parkingRepository) return null; return { systemId: parent.id, }; }, }, }