update initialization of systems in index file

This commit is contained in:
2025-04-07 13:02:13 -07:00
parent e4ff597385
commit 34765a0f3b

View File

@@ -3,17 +3,20 @@ import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone"; import { startStandaloneServer } from "@apollo/server/standalone";
import { MergedResolvers } from "./MergedResolvers"; import { MergedResolvers } from "./MergedResolvers";
import { ServerContext } from "./ServerContext"; import { ServerContext } from "./ServerContext";
import { UnoptimizedInMemoryShuttleRepository } from "./repositories/UnoptimizedInMemoryShuttleRepository"; import { loadShuttleTestData, supportedIntegrationTestSystems } from "./loaders/loadShuttleTestData";
import { TimedApiBasedShuttleRepositoryLoader } from "./loaders/TimedApiBasedShuttleRepositoryLoader"; import { InterchangeSystem, InterchangeSystemBuilderArguments } from "./entities/InterchangeSystem";
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";
const typeDefs = readFileSync("./schema.graphqls", "utf8"); 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() { async function main() {
const server = new ApolloServer<ServerContext>({ const server = new ApolloServer<ServerContext>({
typeDefs, typeDefs,
@@ -21,39 +24,27 @@ async function main() {
introspection: process.env.NODE_ENV !== "production", introspection: process.env.NODE_ENV !== "production",
}); });
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository(); let systems: InterchangeSystem[];
let notificationRepository: NotificationRepository;
let notificationService: ETANotificationScheduler;
if (process.argv.length > 2 && process.argv[2] == "integration-testing") { if (process.argv.length > 2 && process.argv[2] == "integration-testing") {
console.log("Using integration testing setup") console.log("Using integration testing setup")
await loadShuttleTestData(shuttleRepository);
const appleNotificationSender = new AppleNotificationSender(false); systems = await Promise.all(supportedIntegrationTestSystems.map(
notificationRepository = new InMemoryNotificationRepository(); async (systemArguments) => {
const system = InterchangeSystem.buildForTesting(systemArguments);
notificationService = new ETANotificationScheduler( // Have loading of different data for different systems in the future
shuttleRepository, await loadShuttleTestData(system.shuttleRepository);
notificationRepository,
appleNotificationSender return system;
); }
notificationService.startListeningForUpdates(); ));
} else { } else {
const repositoryDataUpdater = new TimedApiBasedShuttleRepositoryLoader( systems = await Promise.all(supportedSystems.map(
shuttleRepository, async (systemArguments) => {
); return InterchangeSystem.buildForTesting(systemArguments);
await repositoryDataUpdater.start(); },
));
const redisNotificationRepository = new RedisNotificationRepository();
await redisNotificationRepository.connect();
notificationRepository = redisNotificationRepository;
notificationService = new ETANotificationScheduler(
shuttleRepository,
notificationRepository
);
notificationService.startListeningForUpdates();
} }
const { url } = await startStandaloneServer(server, { const { url } = await startStandaloneServer(server, {
@@ -62,8 +53,14 @@ async function main() {
}, },
context: async () => { context: async () => {
return { return {
shuttleRepository, systems,
notificationRepository, findSystemById: (id: string) => {
const system = systems.find((system) => system.id === id);
if (!system) {
return null;
}
return system;
},
} }
}, },
}); });