update server context to only include the notification repository

This commit is contained in:
2025-03-27 10:42:43 -07:00
parent bda46d6808
commit 3761f43909
7 changed files with 32 additions and 22 deletions

View File

@@ -1,7 +1,8 @@
import { ETANotificationScheduler } from "./notifications/schedulers/ETANotificationScheduler";
import { ShuttleGetterSetterRepository } from "./repositories/ShuttleGetterSetterRepository";
import { NotificationRepository } from "./repositories/NotificationRepository";
export interface ServerContext {
shuttleRepository: ShuttleGetterSetterRepository;
notificationService: ETANotificationScheduler;
notificationRepository: NotificationRepository;
}

View File

@@ -9,6 +9,7 @@ import { ETANotificationScheduler } from "./notifications/schedulers/ETANotifica
import { loadShuttleTestData } from "./loaders/loadShuttleTestData";
import { AppleNotificationSender } from "./notifications/senders/AppleNotificationSender";
import { InMemoryNotificationRepository } from "./repositories/InMemoryNotificationRepository";
import { NotificationRepository } from "./repositories/NotificationRepository";
const typeDefs = readFileSync("./schema.graphqls", "utf8");
@@ -19,25 +20,32 @@ async function main() {
introspection: process.env.NODE_ENV !== "production",
});
const repository = new UnoptimizedInMemoryShuttleRepository();
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
let notificationRepository: NotificationRepository;
let notificationService: ETANotificationScheduler;
if (process.argv.length > 2 && process.argv[2] == "integration-testing") {
console.log("Using integration testing setup")
await loadShuttleTestData(repository);
await loadShuttleTestData(shuttleRepository);
const appleNotificationSender = new AppleNotificationSender(false);
const inMemoryNotificationRepository = new InMemoryNotificationRepository();
notificationRepository = new InMemoryNotificationRepository();
notificationService = new ETANotificationScheduler(
repository,
inMemoryNotificationRepository,
shuttleRepository,
notificationRepository,
appleNotificationSender
);
} else {
const repositoryDataUpdater = new TimedApiBasedShuttleRepositoryLoader(
repository
shuttleRepository,
);
await repositoryDataUpdater.start();
notificationService = new ETANotificationScheduler(repository);
notificationRepository = new InMemoryNotificationRepository();
notificationService = new ETANotificationScheduler(
shuttleRepository,
notificationRepository
);
}
const { url } = await startStandaloneServer(server, {
@@ -46,8 +54,8 @@ async function main() {
},
context: async () => {
return {
repository,
notificationService,
shuttleRepository,
notificationRepository,
}
},
});

View File

@@ -30,7 +30,7 @@ export const MutationResolvers: Resolvers<ServerContext> = {
: ETANotificationScheduler.defaultSecondsThresholdForNotificationToFire,
}
await context.notificationService.scheduleNotification(notificationData);
await context.notificationRepository.scheduleNotification(notificationData);
const response: NotificationResponse = {
message: "Notification scheduled",
@@ -40,8 +40,8 @@ export const MutationResolvers: Resolvers<ServerContext> = {
return response;
},
cancelNotification: async (_parent, args, context, _info) => {
if (context.notificationService.isNotificationScheduled(args.input)) {
await context.notificationService.cancelNotificationIfExists(args.input);
if (context.notificationRepository.isNotificationScheduled(args.input)) {
await context.notificationRepository.cancelNotificationIfExists(args.input);
return {
success: true,
message: "Notification cancelled",

View File

@@ -18,11 +18,11 @@ export const QueryResolvers: Resolvers<ServerContext> = {
},
isNotificationScheduled: async (_parent, args, contextValue, _info) => {
const notificationData = args.input;
return contextValue.notificationService.isNotificationScheduled(notificationData);
return contextValue.notificationRepository.isNotificationScheduled(notificationData);
},
secondsThresholdForNotification: async (_parent, args, contextValue, _info) => {
const notificationData = args.input;
return contextValue.notificationService.getSecondsThresholdForScheduledNotification(notificationData);
return contextValue.notificationRepository.getSecondsThresholdForScheduledNotification(notificationData);
},
},
}