mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add the code to associate tuple key with array of device ids
This commit is contained in:
@@ -2,6 +2,7 @@ import { GetterRepository } from "../repositories/GetterRepository";
|
|||||||
import * as crypto from "node:crypto";
|
import * as crypto from "node:crypto";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import { TupleKey } from "../types/TupleKey";
|
||||||
|
|
||||||
interface ScheduledNotificationData {
|
interface ScheduledNotificationData {
|
||||||
deviceId: string;
|
deviceId: string;
|
||||||
@@ -78,6 +79,13 @@ export class NotificationService {
|
|||||||
*/
|
*/
|
||||||
public async scheduleNotification({ deviceId, shuttleId, stopId }: ScheduledNotificationData) {
|
public async scheduleNotification({ deviceId, shuttleId, stopId }: ScheduledNotificationData) {
|
||||||
// Associate TupleKey(shuttleId, stopId) with array of device IDs
|
// 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
|
// Refresh the subscriber with the updated array if needed
|
||||||
|
|
||||||
// In the subscriber callback:
|
// In the subscriber callback:
|
||||||
@@ -103,7 +111,11 @@ export class NotificationService {
|
|||||||
* @param stopId
|
* @param stopId
|
||||||
*/
|
*/
|
||||||
public isNotificationScheduled({ deviceId, shuttleId, stopId }: ScheduledNotificationData): boolean {
|
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) {
|
public cancelAllNotifications(deviceId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user