add the code to associate tuple key with array of device ids

This commit is contained in:
2025-02-03 21:31:18 -08:00
parent 69525a643d
commit 3bdc730c95

View File

@@ -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,8 +111,12 @@ export class NotificationService {
* @param stopId
*/
public isNotificationScheduled({ deviceId, shuttleId, stopId }: ScheduledNotificationData): boolean {
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) {