move arguments and notification interfaces to notification repository file

This commit is contained in:
2025-03-27 09:57:49 -07:00
parent 60b626b64f
commit 09be37cedb
4 changed files with 44 additions and 23 deletions

View File

@@ -2,22 +2,10 @@ import { ShuttleGetterRepository } from "../../repositories/ShuttleGetterReposit
import { TupleKey } from "../../types/TupleKey";
import { IEta } from "../../entities/entities";
import { AppleNotificationSender, NotificationAlertArguments } from "../senders/AppleNotificationSender";
export interface NotificationLookupArguments {
deviceId: string;
shuttleId: string;
stopId: string;
}
export interface NotificationSchedulingArguments extends NotificationLookupArguments {
/**
* Value which specifies the ETA of the shuttle for when
* the notification should fire.
* For example, a secondsThreshold of 180 would mean that the notification
* fires when the ETA drops below 3 minutes.
*/
secondsThreshold: number;
}
import {
NotificationLookupArguments,
ScheduledNotification
} from "../../repositories/NotificationRepository";
type DeviceIdSecondsThresholdAssociation = { [key: string]: number };
@@ -47,7 +35,7 @@ export class ETANotificationScheduler {
*/
private deviceIdsToDeliverTo: { [key: string]: DeviceIdSecondsThresholdAssociation } = {}
private async sendEtaNotificationImmediately(notificationData: NotificationSchedulingArguments): Promise<boolean> {
private async sendEtaNotificationImmediately(notificationData: ScheduledNotification): Promise<boolean> {
const { deviceId, shuttleId, stopId } = notificationData;
const shuttle = await this.shuttleRepository.getShuttleById(shuttleId);
@@ -85,7 +73,7 @@ export class ETANotificationScheduler {
const deviceIdsToRemove = new Set<string>();
for (let deviceId of Object.keys(this.deviceIdsToDeliverTo[tupleKey])) {
const scheduledNotificationData: NotificationSchedulingArguments = {
const scheduledNotificationData: ScheduledNotification = {
deviceId,
secondsThreshold: this.deviceIdsToDeliverTo[tupleKey][deviceId],
shuttleId: eta.shuttleId,
@@ -103,7 +91,7 @@ export class ETANotificationScheduler {
});
}
private async sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold(notificationObject: NotificationSchedulingArguments, etaSecondsRemaining: number) {
private async sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold(notificationObject: ScheduledNotification, etaSecondsRemaining: number) {
if (etaSecondsRemaining > notificationObject.secondsThreshold) {
return false;
}
@@ -119,7 +107,7 @@ export class ETANotificationScheduler {
* @param secondsThreshold Value which specifies the ETA of the shuttle for when
* the notification should fire.
*/
public async scheduleNotification({ deviceId, shuttleId, stopId, secondsThreshold }: NotificationSchedulingArguments) {
public async scheduleNotification({ deviceId, shuttleId, stopId, secondsThreshold }: ScheduledNotification) {
const tuple = new TupleKey(shuttleId, stopId);
if (this.deviceIdsToDeliverTo[tuple.toString()] === undefined) {
this.deviceIdsToDeliverTo[tuple.toString()] = {};
@@ -169,7 +157,7 @@ export class ETANotificationScheduler {
* @param deviceId
*/
public async getAllScheduledNotificationsForDevice(deviceId: string): Promise<NotificationLookupArguments[]> {
const scheduledNotifications: NotificationSchedulingArguments[] = [];
const scheduledNotifications: ScheduledNotification[] = [];
for (const key of Object.keys(this.deviceIdsToDeliverTo)) {
if (deviceId in this.deviceIdsToDeliverTo[key]) {

View File

@@ -0,0 +1,33 @@
export interface NotificationLookupArguments {
deviceId: string;
shuttleId: string;
stopId: string;
}
export interface ScheduledNotification extends NotificationLookupArguments {
/**
* Value which specifies the ETA of the shuttle for when
* the notification should fire.
* For example, a secondsThreshold of 180 would mean that the notification
* fires when the ETA drops below 3 minutes.
*/
secondsThreshold: number;
}
export class NotificationRepository {
public async getAllNotificationsForShuttleAndStopId(shuttleId: string, stopId: string) {
}
public async getSecondsThresholdForNotificationIfExists(lookupArguments: NotificationLookupArguments) {
}
public async addNotification(notification: ScheduledNotification) {
}
public async deleteNotification(lookupArguments: NotificationLookupArguments) {
}
}

View File

@@ -2,7 +2,7 @@ import { NotificationResponse, Resolvers } from "../generated/graphql";
import { ServerContext } from "../ServerContext";
import {
ETANotificationScheduler,
NotificationSchedulingArguments
ScheduledNotification
} from "../notifications/schedulers/ETANotificationScheduler";
export const MutationResolvers: Resolvers<ServerContext> = {