mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
update system resolvers
This commit is contained in:
@@ -4,14 +4,29 @@ import { ServerContext } from "../ServerContext";
|
||||
export const SystemResolvers: Resolvers<ServerContext> = {
|
||||
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<ServerContext> = {
|
||||
},
|
||||
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<ServerContext> = {
|
||||
},
|
||||
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<ServerContext> = {
|
||||
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);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user