From ed2b7dbe5e292050b7f1e1a6f22cb40a17f4338d Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Sun, 6 Apr 2025 11:03:41 -0700 Subject: [PATCH] update query resolvers to work with updated context --- src/resolvers/QueryResolvers.ts | 34 ++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/resolvers/QueryResolvers.ts b/src/resolvers/QueryResolvers.ts index 1b316c8..34c31e3 100644 --- a/src/resolvers/QueryResolvers.ts +++ b/src/resolvers/QueryResolvers.ts @@ -4,25 +4,49 @@ import { Resolvers } from "../generated/graphql"; export const QueryResolvers: Resolvers = { Query: { systems: async (_parent, args, contextValue, _info) => { - return await contextValue.shuttleRepository.getSystemIfExists(); + return contextValue.systems.map((system) => { + return { + name: system.name, + id: system.id, + }; + }) }, system: async (_parent, args, contextValue, _info) => { if (!args.id) return null; - const system = await contextValue.shuttleRepository.getSystemById(args.id); - if (system === null) return null; + const system = contextValue.systems.find((system) => { + return system.id === args.id; + }); + if (system === undefined) return null; return { name: system.name, id: system.id, }; }, + // TODO: Update the GraphQL schema to require a system ID isNotificationScheduled: async (_parent, args, contextValue, _info) => { const notificationData = args.input; - return await contextValue.notificationRepository.isNotificationScheduled(notificationData); + + for (let system of contextValue.systems) { + const isScheduled = await system.notificationRepository.isNotificationScheduled(notificationData); + if (isScheduled) { + return true; + } + } + + return false; }, secondsThresholdForNotification: async (_parent, args, contextValue, _info) => { const notificationData = args.input; - return await contextValue.notificationRepository.getSecondsThresholdForNotificationIfExists(notificationData); + + for (let system of contextValue.systems) { + const isScheduled = await system.notificationRepository.isNotificationScheduled(notificationData); + if (isScheduled) { + return await system.notificationRepository.getSecondsThresholdForNotificationIfExists(args.input); + } + } + + return null; }, }, }