mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Make BaseRedisRepository extend EventEmitter; make RedisShuttleRepository extend BaseRedisRepository
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
import { BaseRedisRepository } from "../BaseRedisRepository";
|
||||
|
||||
export class RedisNotificationRepository extends BaseRedisRepository implements NotificationRepository {
|
||||
private listeners: Listener[] = [];
|
||||
private notificationListeners: Listener[] = [];
|
||||
private readonly NOTIFICATION_KEY_PREFIX = 'notification:';
|
||||
|
||||
private getNotificationKey = (shuttleId: string, stopId: string): string => {
|
||||
@@ -23,7 +23,7 @@ export class RedisNotificationRepository extends BaseRedisRepository implements
|
||||
|
||||
await this.redisClient.hSet(key, deviceId, secondsThreshold.toString());
|
||||
|
||||
this.listeners.forEach((listener: Listener) => {
|
||||
this.notificationListeners.forEach((listener: Listener) => {
|
||||
const event: NotificationEvent = {
|
||||
event: 'addOrUpdate',
|
||||
notification
|
||||
@@ -46,7 +46,7 @@ export class RedisNotificationRepository extends BaseRedisRepository implements
|
||||
await this.redisClient.del(key);
|
||||
}
|
||||
|
||||
this.listeners.forEach((listener) => {
|
||||
this.notificationListeners.forEach((listener) => {
|
||||
const event: NotificationEvent = {
|
||||
event: 'delete',
|
||||
notification: {
|
||||
@@ -94,20 +94,20 @@ export class RedisNotificationRepository extends BaseRedisRepository implements
|
||||
};
|
||||
|
||||
public subscribeToNotificationChanges = (listener: Listener): void => {
|
||||
const index = this.listeners.findIndex(
|
||||
const index = this.notificationListeners.findIndex(
|
||||
(existingListener) => existingListener === listener
|
||||
);
|
||||
if (index < 0) {
|
||||
this.listeners.push(listener);
|
||||
this.notificationListeners.push(listener);
|
||||
}
|
||||
};
|
||||
|
||||
public unsubscribeFromNotificationChanges = (listener: Listener): void => {
|
||||
const index = this.listeners.findIndex(
|
||||
const index = this.notificationListeners.findIndex(
|
||||
(existingListener) => existingListener === listener
|
||||
);
|
||||
if (index >= 0) {
|
||||
this.listeners.splice(index, 1);
|
||||
this.notificationListeners.splice(index, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user