add findSystemById method on server context

This commit is contained in:
2025-04-06 11:34:37 -07:00
parent ea4723df85
commit 8dd2f02783
3 changed files with 11 additions and 10 deletions

View File

@@ -2,4 +2,5 @@ import { InterchangeSystem } from "./entities/InterchangeSystem";
export interface ServerContext {
systems: InterchangeSystem[];
findSystemById: (id: string) => InterchangeSystem | null;
}

View File

@@ -4,14 +4,14 @@ import { ServerContext } from "../ServerContext";
export const StopResolvers: Resolvers<ServerContext> = {
Stop: {
orderedStops: async (parent, args, contextValue, _info) => {
const system = contextValue.systems.find((system) => system.id === parent.id);
const system = contextValue.findSystemById(parent.id);
if (!system) {
return [];
}
return await system.shuttleRepository.getOrderedStopsByStopId(parent.id);
},
etas: async (parent, args, contextValue, _info) => {
const system = contextValue.systems.find((system) => system.id === parent.id);
const system = contextValue.findSystemById(parent.id);
if (!system) {
return [];
}

View File

@@ -3,16 +3,16 @@ import { ServerContext } from "../ServerContext";
export const SystemResolvers: Resolvers<ServerContext> = {
System: {
routes: async (parent, args, contextValue, _info) => {
const system = contextValue.systems.find((system) => system.id === parent.id);
routes: async (parent, _args, contextValue, _info) => {
const system = contextValue.findSystemById(parent.id);
if (!system) {
return [];
}
return await system.shuttleRepository.getRoutesBySystemId(parent.id);
},
stops: async (parent, args, contextValue, _info) => {
const system = contextValue.systems.find((system) => system.id === parent.id);
stops: async (parent, _args, contextValue, _info) => {
const system = contextValue.findSystemById(parent.id);
if (!system) {
return [];
}
@@ -21,7 +21,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
},
stop: async (parent, args, contextValue, _info) => {
if (!args.id) return null;
const system = contextValue.systems.find((system) => system.id === parent.id);
const system = contextValue.findSystemById(parent.id);
if (!system) {
return null;
}
@@ -40,7 +40,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
},
route: async (parent, args, contextValue, _info) => {
if (!args.id) return null;
const system = contextValue.systems.find((system) => system.id === parent.id);
const system = contextValue.findSystemById(parent.id);
if (!system) {
return null;
}
@@ -59,7 +59,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
},
shuttle: async (parent, args, contextValue, _info) => {
if (!args.id) return null;
const system = contextValue.systems.find((system) => system.id === parent.id);
const system = contextValue.findSystemById(parent.id);
if (!system) {
return null;
}
@@ -71,7 +71,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
return shuttle;
},
shuttles: async (parent, args, contextValue, _info) => {
const system = contextValue.systems.find((system) => system.id === parent.id);
const system = contextValue.findSystemById(parent.id);
if (!system) {
return [];
}