From 3bdc730c95e5a4851187e017e0843a84e0e8d59e Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 3 Feb 2025 21:31:18 -0800 Subject: [PATCH] add the code to associate tuple key with array of device ids --- src/services/NotificationService.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/services/NotificationService.ts b/src/services/NotificationService.ts index 2f6f6a5..ec388c6 100644 --- a/src/services/NotificationService.ts +++ b/src/services/NotificationService.ts @@ -2,6 +2,7 @@ import { GetterRepository } from "../repositories/GetterRepository"; import * as crypto from "node:crypto"; import jwt from "jsonwebtoken"; import fs from "fs"; +import { TupleKey } from "../types/TupleKey"; interface ScheduledNotificationData { deviceId: string; @@ -78,6 +79,13 @@ export class NotificationService { */ public async scheduleNotification({ deviceId, shuttleId, stopId }: ScheduledNotificationData) { // Associate TupleKey(shuttleId, stopId) with array of device IDs + const tuple = new TupleKey(shuttleId, stopId); + if (this.deviceIdsToDeliverTo[tuple.toString()] === undefined) { + this.deviceIdsToDeliverTo[tuple.toString()] = [deviceId]; + } else { + this.deviceIdsToDeliverTo[tuple.toString()].push(deviceId); + } + // Refresh the subscriber with the updated array if needed // In the subscriber callback: @@ -103,7 +111,11 @@ export class NotificationService { * @param stopId */ public isNotificationScheduled({ deviceId, shuttleId, stopId }: ScheduledNotificationData): boolean { - return false; + const tuple = new TupleKey(shuttleId, stopId); + if (this.deviceIdsToDeliverTo[tuple.toString()] === undefined) { + return false; + } + return this.deviceIdsToDeliverTo[tuple.toString()].includes(deviceId); } public cancelAllNotifications(deviceId: string) {