From 9ff388f2d44b379b0496422ff9921c0d1a511e31 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Sun, 6 Apr 2025 11:10:16 -0700 Subject: [PATCH] update system resolvers --- src/resolvers/SystemResolvers.ts | 40 +++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/resolvers/SystemResolvers.ts b/src/resolvers/SystemResolvers.ts index ae9903a..415d0b3 100644 --- a/src/resolvers/SystemResolvers.ts +++ b/src/resolvers/SystemResolvers.ts @@ -4,14 +4,29 @@ import { ServerContext } from "../ServerContext"; export const SystemResolvers: Resolvers = { System: { routes: async (parent, args, contextValue, info) => { - return await contextValue.shuttleRepository.getRoutesBySystemId(parent.id); + const system = contextValue.systems.find((system) => system.id === parent.id); + if (!system) { + return []; + } + + return await system.shuttleRepository.getRoutesBySystemId(parent.id); }, stops: async (parent, args, contextValue, info) => { - return await contextValue.shuttleRepository.getStopsBySystemId(parent.id); + const system = contextValue.systems.find((system) => system.id === parent.id); + if (!system) { + return []; + } + + return await system.shuttleRepository.getStopsBySystemId(parent.id); }, stop: async (parent, args, contextValue, info) => { if (!args.id) return null; - const stop = await contextValue.shuttleRepository.getStopById(args.id); + const system = contextValue.systems.find((system) => system.id === 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; @@ -24,7 +39,11 @@ export const SystemResolvers: Resolvers = { }, route: async (parent, args, contextValue, info) => { if (!args.id) return null; - const route = await contextValue.shuttleRepository.getRouteById(args.id); + const system = contextValue.systems.find((system) => system.id === 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; @@ -38,7 +57,11 @@ export const SystemResolvers: Resolvers = { }, shuttle: async (parent, args, contextValue, info) => { if (!args.id) return null; - const shuttle = await contextValue.shuttleRepository.getShuttleById(args.id); + const system = contextValue.systems.find((system) => system.id === 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; @@ -46,7 +69,12 @@ export const SystemResolvers: Resolvers = { return shuttle; }, shuttles: async (parent, args, contextValue, info) => { - return await contextValue.shuttleRepository.getShuttlesBySystemId(parent.id); + const system = contextValue.systems.find((system) => system.id === parent.id); + if (!system) { + return []; + } + + return await system.shuttleRepository.getShuttlesBySystemId(parent.id); } }, }