mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
update query resolvers to work with updated context
This commit is contained in:
@@ -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;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user