From 442179b8053cbb0765dc9d109ec6b050a04e8fc1 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Thu, 26 Dec 2024 18:05:07 -0800 Subject: [PATCH] implement shuttle/route resolvers --- src/resolvers.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/resolvers.ts b/src/resolvers.ts index bfdadcf..54d05c6 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -85,6 +85,15 @@ export const resolvers: Resolvers = { id: shuttle.id, name: shuttle.name, }; + }, + shuttles: async (parent, args, contextValue, info) => { + const shuttles = await contextValue.repository.getShuttlesBySystemId(parent.id); + + return shuttles.map(shuttle => ({ + coordinates: shuttle.coordinates, + name: shuttle.name, + id: shuttle.id, + })); } }, Route: { @@ -149,6 +158,20 @@ export const resolvers: Resolvers = { } return []; + }, + route: async (parent, args, contextValue, info) => { + const shuttle = await contextValue.repository.getShuttleById(parent.id); + if (shuttle === null) return null; + + const route = await contextValue.repository.getRouteById(shuttle?.routeId); + if (route === null) return null; + + return { + color: route.color, + id: route.id, + name: route.name, + polylineCoordinates: route.polylineCoordinates, + } } }, Stop: {