mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
import { OrderedStop, Resolvers } from "../generated/graphql";
|
|
import { ServerContext } from "../ServerContext";
|
|
|
|
export const OrderedStopResolvers: Resolvers<ServerContext> = {
|
|
OrderedStop: {
|
|
nextStop: async (parent, args, contextValue, _info): Promise<OrderedStop | null> => {
|
|
const routeId = parent.routeId;
|
|
const stopId = parent.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 system.shuttleRepository.getStopById(nextOrderedStop.stopId);
|
|
if (!nextOrderedStopObject) return null;
|
|
|
|
return {
|
|
route: parent.route,
|
|
routeId: parent.routeId,
|
|
stopId: nextOrderedStopObject.id,
|
|
systemId: system.id,
|
|
}
|
|
},
|
|
previousStop: async (parent, args, contextValue, _info): Promise<OrderedStop | null> => {
|
|
const routeId = parent.routeId;
|
|
const stopId = parent.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 system.shuttleRepository.getStopById(previousOrderedStop.stopId);
|
|
if (!previousOrderedStopObject) return null;
|
|
|
|
return {
|
|
route: parent.route,
|
|
routeId: parent.routeId,
|
|
stopId: previousOrderedStopObject.id,
|
|
systemId: system.id,
|
|
}
|
|
},
|
|
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) => {
|
|
if (!parent.stop) return null;
|
|
const system = contextValue.findSystemById(parent.stop.systemId);
|
|
if (!system) return null;
|
|
|
|
return await system.shuttleRepository.getRouteById(parent.routeId);
|
|
},
|
|
},
|
|
|
|
}
|