Files
project-inter-server/src/resolvers/RouteResolvers.ts

39 lines
1.1 KiB
TypeScript

import { Coordinates, Resolvers } from "../generated/graphql";
import { ServerContext } from "../ServerContext";
export const RouteResolvers: Resolvers<ServerContext> = {
Route: {
shuttles: async (parent, args, contextValue, info) => {
const shuttles = await contextValue.shuttleRepository.getShuttlesByRouteId(parent.id);
return shuttles.map(({
coordinates,
name,
id,
orientationInDegrees
}) => ({
coordinates: coordinates as Coordinates,
name,
route: parent,
routeId: parent.id,
id,
orientationInDegrees
}));
},
orderedStop: async (parent, args, contextValue, info) => {
if (!args.forStopId) return null;
const orderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(parent.id, args.forStopId);
if (!orderedStop) return null;
const stop = await contextValue.shuttleRepository.getStopById(orderedStop.stopId);
if (!stop) return null;
return {
stopId: args.forStopId,
routeId: parent.id,
route: parent,
}
},
},
}