update route resolvers

This commit is contained in:
2025-04-06 11:38:46 -07:00
parent 28c3e2f5f5
commit 1629f79299

View File

@@ -4,7 +4,10 @@ import { ServerContext } from "../ServerContext";
export const RouteResolvers: Resolvers<ServerContext> = {
Route: {
shuttles: async (parent, args, contextValue, info) => {
const shuttles = await contextValue.shuttleRepository.getShuttlesByRouteId(parent.id);
const system = contextValue.findSystemById(parent.systemId);
if (!system) return null;
const shuttles = await system.shuttleRepository.getShuttlesByRouteId(parent.id);
return shuttles.map(({
coordinates,
@@ -17,15 +20,20 @@ export const RouteResolvers: Resolvers<ServerContext> = {
route: parent,
routeId: parent.id,
id,
orientationInDegrees
orientationInDegrees,
systemId: parent.systemId,
}));
},
orderedStop: async (parent, args, contextValue, info) => {
if (!args.forStopId) return null;
const orderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(parent.id, args.forStopId);
const system = contextValue.findSystemById(parent.systemId);
if (!system) return null;
const orderedStop = await system.shuttleRepository.getOrderedStopByRouteAndStopId(parent.id, args.forStopId);
if (!orderedStop) return null;
const stop = await contextValue.shuttleRepository.getStopById(orderedStop.stopId);
const stop = await system.shuttleRepository.getStopById(orderedStop.stopId);
if (!stop) return null;
return {