mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Implement remaining logic for RedisExternalSourceETARepository
This commit is contained in:
@@ -6,7 +6,7 @@ export abstract class BaseRedisETARepository extends BaseRedisRepository impleme
|
|||||||
private static readonly ETA_KEY_PREFIX = 'shuttle:eta:';
|
private static readonly ETA_KEY_PREFIX = 'shuttle:eta:';
|
||||||
|
|
||||||
// Helper methods
|
// Helper methods
|
||||||
private createEtaKey = (shuttleId: string, stopId: string) =>
|
protected createEtaKey = (shuttleId: string, stopId: string) =>
|
||||||
`${BaseRedisETARepository.ETA_KEY_PREFIX}${shuttleId}:${stopId}`;
|
`${BaseRedisETARepository.ETA_KEY_PREFIX}${shuttleId}:${stopId}`;
|
||||||
|
|
||||||
createRedisHashFromEta = (eta: IEta): Record<string, string> => ({
|
createRedisHashFromEta = (eta: IEta): Record<string, string> => ({
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
import { IEta } from "../../../entities/ShuttleRepositoryEntities";
|
import { IEta } from "../../../entities/ShuttleRepositoryEntities";
|
||||||
import { BaseRedisETARepository } from "./BaseRedisETARepository";
|
import { BaseRedisETARepository } from "./BaseRedisETARepository";
|
||||||
import { ExternalSourceETARepository } from "./ExternalSourceETARepository";
|
import { ExternalSourceETARepository } from "./ExternalSourceETARepository";
|
||||||
|
import { ETARepositoryEvent } from "./ETAGetterRepository";
|
||||||
|
|
||||||
export class RedisExternalSourceETARepository extends BaseRedisETARepository implements ExternalSourceETARepository {
|
export class RedisExternalSourceETARepository extends BaseRedisETARepository implements ExternalSourceETARepository {
|
||||||
addOrUpdateEtaFromExternalSource(eta: IEta): Promise<void> {
|
async addOrUpdateEtaFromExternalSource(eta: IEta): Promise<void> {
|
||||||
throw new Error("Method not implemented.");
|
await this.addOrUpdateEta(eta);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeEtaIfExists(shuttleId: string, stopId: string): Promise<IEta | null> {
|
async removeEtaIfExists(shuttleId: string, stopId: string): Promise<IEta | null> {
|
||||||
throw new Error("Method not implemented.");
|
const existingEta = await this.getEtaForShuttleAndStopId(shuttleId, stopId);
|
||||||
|
if (existingEta === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = this.createEtaKey(shuttleId, stopId);
|
||||||
|
await this.redisClient.del(key);
|
||||||
|
this.emit(ETARepositoryEvent.ETA_REMOVED, existingEta);
|
||||||
|
return existingEta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user