mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { Coordinates, Resolvers } from "../generated/graphql";
|
|
import { ServerContext } from "../ServerContext";
|
|
|
|
export const SystemResolvers: Resolvers<ServerContext> = {
|
|
System: {
|
|
routes: async (parent, args, contextValue, info) => {
|
|
return await contextValue.repository.getRoutesBySystemId(parent.id);
|
|
},
|
|
stops: async (parent, args, contextValue, info) => {
|
|
return await contextValue.repository.getStopsBySystemId(parent.id);
|
|
},
|
|
stop: async (parent, args, contextValue, info) => {
|
|
if (!args.id) return null;
|
|
const stop = await contextValue.repository.getStopById(args.id);
|
|
if (stop === null) return null;
|
|
|
|
return {
|
|
id: stop.id,
|
|
name: stop.name,
|
|
coordinates: stop.coordinates as Coordinates,
|
|
};
|
|
},
|
|
route: async (parent, args, contextValue, info) => {
|
|
if (!args.id) return null;
|
|
const route = await contextValue.repository.getRouteById(args.id);
|
|
if (route === null) return null;
|
|
|
|
return {
|
|
color: route.color,
|
|
id: route.id,
|
|
name: route.name,
|
|
polylineCoordinates: route.polylineCoordinates as Coordinates[],
|
|
};
|
|
},
|
|
shuttle: async (parent, args, contextValue, info) => {
|
|
if (!args.id) return null;
|
|
const shuttle = await contextValue.repository.getShuttleById(args.id);
|
|
if (shuttle === null) return null;
|
|
|
|
return shuttle;
|
|
},
|
|
shuttles: async (parent, args, contextValue, info) => {
|
|
return await contextValue.repository.getShuttlesBySystemId(parent.id);
|
|
}
|
|
},
|
|
} |