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