mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
update initialization of systems in index file
This commit is contained in:
71
src/index.ts
71
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<ServerContext>({
|
||||
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;
|
||||
},
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user