update query resolvers to work with updated context

This commit is contained in:
2025-04-06 11:03:41 -07:00
parent 2d1e3c13d2
commit ed2b7dbe5e

View File

@@ -4,25 +4,49 @@ import { Resolvers } from "../generated/graphql";
export const QueryResolvers: Resolvers<ServerContext> = { export const QueryResolvers: Resolvers<ServerContext> = {
Query: { Query: {
systems: async (_parent, args, contextValue, _info) => { 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) => { system: async (_parent, args, contextValue, _info) => {
if (!args.id) return null; if (!args.id) return null;
const system = await contextValue.shuttleRepository.getSystemById(args.id); const system = contextValue.systems.find((system) => {
if (system === null) return null; return system.id === args.id;
});
if (system === undefined) return null;
return { return {
name: system.name, name: system.name,
id: system.id, id: system.id,
}; };
}, },
// TODO: Update the GraphQL schema to require a system ID
isNotificationScheduled: async (_parent, args, contextValue, _info) => { isNotificationScheduled: async (_parent, args, contextValue, _info) => {
const notificationData = args.input; 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) => { secondsThresholdForNotification: async (_parent, args, contextValue, _info) => {
const notificationData = args.input; 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;
}, },
}, },
} }