update system resolvers

This commit is contained in:
2025-04-06 11:10:16 -07:00
parent ed2b7dbe5e
commit 9ff388f2d4

View File

@@ -4,14 +4,29 @@ import { ServerContext } from "../ServerContext";
export const SystemResolvers: Resolvers<ServerContext> = { export const SystemResolvers: Resolvers<ServerContext> = {
System: { System: {
routes: async (parent, args, contextValue, info) => { 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) => { 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) => { stop: async (parent, args, contextValue, info) => {
if (!args.id) return null; 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 === null) return null;
if (stop.systemId !== parent.id) return null; if (stop.systemId !== parent.id) return null;
@@ -24,7 +39,11 @@ export const SystemResolvers: Resolvers<ServerContext> = {
}, },
route: async (parent, args, contextValue, info) => { route: async (parent, args, contextValue, info) => {
if (!args.id) return null; 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 === null) return null;
if (route.systemId !== parent.id) return null; if (route.systemId !== parent.id) return null;
@@ -38,7 +57,11 @@ export const SystemResolvers: Resolvers<ServerContext> = {
}, },
shuttle: async (parent, args, contextValue, info) => { shuttle: async (parent, args, contextValue, info) => {
if (!args.id) return null; 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 === null) return null;
if (shuttle.systemId !== parent.id) return null; if (shuttle.systemId !== parent.id) return null;
@@ -46,7 +69,12 @@ export const SystemResolvers: Resolvers<ServerContext> = {
return shuttle; return shuttle;
}, },
shuttles: async (parent, args, contextValue, info) => { 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);
} }
}, },
} }