update ordered stop resolvers

This commit is contained in:
2025-04-06 11:42:33 -07:00
parent 1629f79299
commit 7136f9201d

View File

@@ -3,17 +3,21 @@ import { ServerContext } from "../ServerContext";
export const OrderedStopResolvers: Resolvers<ServerContext> = { export const OrderedStopResolvers: Resolvers<ServerContext> = {
OrderedStop: { OrderedStop: {
nextStop: async (parent, args, contextValue, info): Promise<OrderedStop | null> => { nextStop: async (parent, args, contextValue, _info): Promise<OrderedStop | null> => {
const routeId = parent.routeId; const routeId = parent.routeId;
const stopId = parent.stopId; const stopId = parent.stopId;
const currentOrderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId); if (!parent.stop) return null;
const system = contextValue.findSystemById(parent.stop.systemId);
if (!system) return null;
const currentOrderedStop = await system.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId);
if (!currentOrderedStop) return null; if (!currentOrderedStop) return null;
const nextOrderedStop = currentOrderedStop.nextStop; const nextOrderedStop = currentOrderedStop.nextStop;
if (!nextOrderedStop) return null; if (!nextOrderedStop) return null;
const nextOrderedStopObject = await contextValue.shuttleRepository.getStopById(nextOrderedStop.stopId); const nextOrderedStopObject = await system.shuttleRepository.getStopById(nextOrderedStop.stopId);
if (!nextOrderedStopObject) return null; if (!nextOrderedStopObject) return null;
return { return {
@@ -22,17 +26,21 @@ export const OrderedStopResolvers: Resolvers<ServerContext> = {
stopId: nextOrderedStopObject.id, stopId: nextOrderedStopObject.id,
} }
}, },
previousStop: async (parent, args, contextValue, info): Promise<OrderedStop | null> => { previousStop: async (parent, args, contextValue, _info): Promise<OrderedStop | null> => {
const routeId = parent.routeId; const routeId = parent.routeId;
const stopId = parent.stopId; const stopId = parent.stopId;
const currentOrderedStop = await contextValue.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId); if (!parent.stop) return null;
const system = contextValue.findSystemById(parent.stop.systemId);
if (!system) return null;
const currentOrderedStop = await system.shuttleRepository.getOrderedStopByRouteAndStopId(routeId, stopId);
if (!currentOrderedStop) return null; if (!currentOrderedStop) return null;
const previousOrderedStop = currentOrderedStop.previousStop; const previousOrderedStop = currentOrderedStop.previousStop;
if (!previousOrderedStop) return null; if (!previousOrderedStop) return null;
const previousOrderedStopObject = await contextValue.shuttleRepository.getStopById(previousOrderedStop.stopId); const previousOrderedStopObject = await system.shuttleRepository.getStopById(previousOrderedStop.stopId);
if (!previousOrderedStopObject) return null; if (!previousOrderedStopObject) return null;
return { return {
@@ -41,11 +49,19 @@ export const OrderedStopResolvers: Resolvers<ServerContext> = {
stopId: previousOrderedStopObject.id, stopId: previousOrderedStopObject.id,
} }
}, },
stop: async (parent, args, contextValue, info) => { stop: async (parent, args, contextValue, _info) => {
return await contextValue.shuttleRepository.getStopById(parent.stopId); if (!parent.stop) return null;
const system = contextValue.findSystemById(parent.stop.systemId);
if (!system) return null;
return await system.shuttleRepository.getStopById(parent.stopId);
}, },
route: async (parent, args, contextValue, info) => { route: async (parent, args, contextValue, _info) => {
return await contextValue.shuttleRepository.getRouteById(parent.routeId); if (!parent.stop) return null;
const system = contextValue.findSystemById(parent.stop.systemId);
if (!system) return null;
return await system.shuttleRepository.getRouteById(parent.routeId);
}, },
}, },