mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
move other resolvers into their own files
This commit is contained in:
63
src/resolvers/SystemResolvers.ts
Normal file
63
src/resolvers/SystemResolvers.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
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) => {
|
||||
const stops = await contextValue.repository.getStopsBySystemId(parent.id);
|
||||
return stops.map(({
|
||||
id,
|
||||
name,
|
||||
coordinates
|
||||
}) => ({
|
||||
id,
|
||||
name,
|
||||
// Both ICoordinates and Coordinates have the same definition
|
||||
coordinates: coordinates as Coordinates,
|
||||
}));
|
||||
},
|
||||
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) => {
|
||||
const shuttles = await contextValue.repository.getShuttlesBySystemId(parent.id);
|
||||
|
||||
return shuttles.map(shuttle => ({
|
||||
coordinates: shuttle.coordinates,
|
||||
name: shuttle.name,
|
||||
id: shuttle.id,
|
||||
routeId: shuttle.routeId,
|
||||
}));
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user