mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add findSystemById method on server context
This commit is contained in:
@@ -2,4 +2,5 @@ import { InterchangeSystem } from "./entities/InterchangeSystem";
|
|||||||
|
|
||||||
export interface ServerContext {
|
export interface ServerContext {
|
||||||
systems: InterchangeSystem[];
|
systems: InterchangeSystem[];
|
||||||
|
findSystemById: (id: string) => InterchangeSystem | null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import { ServerContext } from "../ServerContext";
|
|||||||
export const StopResolvers: Resolvers<ServerContext> = {
|
export const StopResolvers: Resolvers<ServerContext> = {
|
||||||
Stop: {
|
Stop: {
|
||||||
orderedStops: async (parent, args, contextValue, _info) => {
|
orderedStops: async (parent, args, contextValue, _info) => {
|
||||||
const system = contextValue.systems.find((system) => system.id === parent.id);
|
const system = contextValue.findSystemById(parent.id);
|
||||||
if (!system) {
|
if (!system) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return await system.shuttleRepository.getOrderedStopsByStopId(parent.id);
|
return await system.shuttleRepository.getOrderedStopsByStopId(parent.id);
|
||||||
},
|
},
|
||||||
etas: async (parent, args, contextValue, _info) => {
|
etas: async (parent, args, contextValue, _info) => {
|
||||||
const system = contextValue.systems.find((system) => system.id === parent.id);
|
const system = contextValue.findSystemById(parent.id);
|
||||||
if (!system) {
|
if (!system) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ 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) => {
|
||||||
const system = contextValue.systems.find((system) => system.id === parent.id);
|
const system = contextValue.findSystemById(parent.id);
|
||||||
if (!system) {
|
if (!system) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return await system.shuttleRepository.getRoutesBySystemId(parent.id);
|
return await system.shuttleRepository.getRoutesBySystemId(parent.id);
|
||||||
},
|
},
|
||||||
stops: async (parent, args, contextValue, _info) => {
|
stops: async (parent, _args, contextValue, _info) => {
|
||||||
const system = contextValue.systems.find((system) => system.id === parent.id);
|
const system = contextValue.findSystemById(parent.id);
|
||||||
if (!system) {
|
if (!system) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
|
|||||||
},
|
},
|
||||||
stop: async (parent, args, contextValue, _info) => {
|
stop: async (parent, args, contextValue, _info) => {
|
||||||
if (!args.id) return null;
|
if (!args.id) return null;
|
||||||
const system = contextValue.systems.find((system) => system.id === parent.id);
|
const system = contextValue.findSystemById(parent.id);
|
||||||
if (!system) {
|
if (!system) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ 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 system = contextValue.systems.find((system) => system.id === parent.id);
|
const system = contextValue.findSystemById(parent.id);
|
||||||
if (!system) {
|
if (!system) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ 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 system = contextValue.systems.find((system) => system.id === parent.id);
|
const system = contextValue.findSystemById(parent.id);
|
||||||
if (!system) {
|
if (!system) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ export const SystemResolvers: Resolvers<ServerContext> = {
|
|||||||
return shuttle;
|
return shuttle;
|
||||||
},
|
},
|
||||||
shuttles: async (parent, args, contextValue, _info) => {
|
shuttles: async (parent, args, contextValue, _info) => {
|
||||||
const system = contextValue.systems.find((system) => system.id === parent.id);
|
const system = contextValue.findSystemById(parent.id);
|
||||||
if (!system) {
|
if (!system) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user