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> = {
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;
},
},
}