mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
move arguments and notification interfaces to notification repository file
This commit is contained in:
@@ -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]) {
|
||||
|
||||
33
src/repositories/NotificationRepository.ts
Normal file
33
src/repositories/NotificationRepository.ts
Normal 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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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> = {
|
||||
|
||||
Reference in New Issue
Block a user