mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
96 lines
3.3 KiB
TypeScript
96 lines
3.3 KiB
TypeScript
import { ShuttleRepositoryLoader } from "../loaders/ShuttleRepositoryLoader";
|
|
import { ETANotificationScheduler } from "../notifications/schedulers/ETANotificationScheduler";
|
|
import { TimedApiBasedShuttleRepositoryLoader } from "../loaders/TimedApiBasedShuttleRepositoryLoader";
|
|
import { UnoptimizedInMemoryShuttleRepository } from "../repositories/UnoptimizedInMemoryShuttleRepository";
|
|
import { RedisNotificationRepository } from "../repositories/RedisNotificationRepository";
|
|
import { NotificationRepository } from "../repositories/NotificationRepository";
|
|
import { ShuttleGetterSetterRepository } from "../repositories/ShuttleGetterSetterRepository";
|
|
import { InMemoryNotificationRepository } from "../repositories/InMemoryNotificationRepository";
|
|
import { AppleNotificationSender } from "../notifications/senders/AppleNotificationSender";
|
|
import { ApiBasedShuttleRepositoryLoader } from "../loaders/ApiBasedShuttleRepositoryLoader";
|
|
|
|
export interface InterchangeSystemBuilderArguments {
|
|
name: string;
|
|
|
|
/**
|
|
* ID to identify the system internally and in the API.
|
|
*/
|
|
id: string;
|
|
|
|
/**
|
|
* ID for fetching shuttle data from the Passio GO! system.
|
|
*/
|
|
passioSystemId: string;
|
|
}
|
|
|
|
export class InterchangeSystem {
|
|
constructor(
|
|
public name: string,
|
|
public id: string,
|
|
public shuttleDataLoader: ShuttleRepositoryLoader,
|
|
public shuttleRepository: ShuttleGetterSetterRepository,
|
|
public notificationScheduler: ETANotificationScheduler,
|
|
public notificationRepository: NotificationRepository,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Construct an instance of the class where all composited
|
|
* classes are correctly linked, meant for use in development and production.
|
|
* @param args
|
|
*/
|
|
static build(
|
|
args: InterchangeSystemBuilderArguments,
|
|
) {
|
|
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
|
|
const shuttleDataLoader = new TimedApiBasedShuttleRepositoryLoader(args.passioSystemId, shuttleRepository);
|
|
|
|
const notificationRepository = new RedisNotificationRepository();
|
|
const notificationScheduler = new ETANotificationScheduler(
|
|
shuttleRepository,
|
|
notificationRepository,
|
|
new AppleNotificationSender(),
|
|
);
|
|
notificationScheduler.startListeningForUpdates();
|
|
|
|
return new InterchangeSystem(
|
|
args.name,
|
|
args.id,
|
|
shuttleDataLoader,
|
|
shuttleRepository,
|
|
notificationScheduler,
|
|
notificationRepository,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Construct an instance of the class where all composited
|
|
* classes are correctly linked, meant for unit tests, and server/app
|
|
* integration tests.
|
|
* @param args
|
|
*/
|
|
static buildForTesting(
|
|
args: InterchangeSystemBuilderArguments,
|
|
) {
|
|
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
|
|
const shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(args.passioSystemId, shuttleRepository);
|
|
|
|
const notificationRepository = new InMemoryNotificationRepository();
|
|
const notificationScheduler = new ETANotificationScheduler(
|
|
shuttleRepository,
|
|
notificationRepository,
|
|
new AppleNotificationSender(false),
|
|
);
|
|
notificationScheduler.startListeningForUpdates();
|
|
|
|
return new InterchangeSystem(
|
|
args.name,
|
|
args.id,
|
|
shuttleDataLoader,
|
|
shuttleRepository,
|
|
notificationScheduler,
|
|
notificationRepository,
|
|
);
|
|
}
|
|
}
|