From 34765a0f3bd7ed79100c640b44a239368f6eb8df Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 7 Apr 2025 13:02:13 -0700 Subject: [PATCH] update initialization of systems in index file --- src/index.ts | 71 +++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/src/index.ts b/src/index.ts index de49b21..a169a0c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,17 +3,20 @@ import { ApolloServer } from "@apollo/server"; import { startStandaloneServer } from "@apollo/server/standalone"; import { MergedResolvers } from "./MergedResolvers"; import { ServerContext } from "./ServerContext"; -import { UnoptimizedInMemoryShuttleRepository } from "./repositories/UnoptimizedInMemoryShuttleRepository"; -import { TimedApiBasedShuttleRepositoryLoader } from "./loaders/TimedApiBasedShuttleRepositoryLoader"; -import { ETANotificationScheduler } from "./notifications/schedulers/ETANotificationScheduler"; -import { loadShuttleTestData } from "./loaders/loadShuttleTestData"; -import { AppleNotificationSender } from "./notifications/senders/AppleNotificationSender"; -import { InMemoryNotificationRepository } from "./repositories/InMemoryNotificationRepository"; -import { NotificationRepository } from "./repositories/NotificationRepository"; -import { RedisNotificationRepository } from "./repositories/RedisNotificationRepository"; +import { loadShuttleTestData, supportedIntegrationTestSystems } from "./loaders/loadShuttleTestData"; +import { InterchangeSystem, InterchangeSystemBuilderArguments } from "./entities/InterchangeSystem"; const typeDefs = readFileSync("./schema.graphqls", "utf8"); +// In the future this can be stored as a separate file +const supportedSystems: InterchangeSystemBuilderArguments[] = [ + { + id: "1", + passioSystemId: "263", + name: "Chapman University", + } +] + async function main() { const server = new ApolloServer({ typeDefs, @@ -21,39 +24,27 @@ async function main() { introspection: process.env.NODE_ENV !== "production", }); - const shuttleRepository = new UnoptimizedInMemoryShuttleRepository(); - - let notificationRepository: NotificationRepository; - let notificationService: ETANotificationScheduler; + let systems: InterchangeSystem[]; if (process.argv.length > 2 && process.argv[2] == "integration-testing") { console.log("Using integration testing setup") - await loadShuttleTestData(shuttleRepository); - const appleNotificationSender = new AppleNotificationSender(false); - notificationRepository = new InMemoryNotificationRepository(); + systems = await Promise.all(supportedIntegrationTestSystems.map( + async (systemArguments) => { + const system = InterchangeSystem.buildForTesting(systemArguments); - notificationService = new ETANotificationScheduler( - shuttleRepository, - notificationRepository, - appleNotificationSender - ); - notificationService.startListeningForUpdates(); + // Have loading of different data for different systems in the future + await loadShuttleTestData(system.shuttleRepository); + + return system; + } + )); } else { - const repositoryDataUpdater = new TimedApiBasedShuttleRepositoryLoader( - shuttleRepository, - ); - await repositoryDataUpdater.start(); - - const redisNotificationRepository = new RedisNotificationRepository(); - await redisNotificationRepository.connect(); - - notificationRepository = redisNotificationRepository; - notificationService = new ETANotificationScheduler( - shuttleRepository, - notificationRepository - ); - notificationService.startListeningForUpdates(); + systems = await Promise.all(supportedSystems.map( + async (systemArguments) => { + return InterchangeSystem.buildForTesting(systemArguments); + }, + )); } const { url } = await startStandaloneServer(server, { @@ -62,8 +53,14 @@ async function main() { }, context: async () => { return { - shuttleRepository, - notificationRepository, + systems, + findSystemById: (id: string) => { + const system = systems.find((system) => system.id === id); + if (!system) { + return null; + } + return system; + }, } }, });