23 lines
906 B
TypeScript
23 lines
906 B
TypeScript
import { IEta } from "../../../entities/ShuttleRepositoryEntities";
|
|
import { ExternalSourceETARepository } from "./ExternalSourceETARepository";
|
|
import { BaseInMemoryETARepository } from "./BaseInMemoryETARepository";
|
|
import { ETARepositoryEvent } from "./ETAGetterRepository";
|
|
|
|
export class InMemoryExternalSourceETARepository extends BaseInMemoryETARepository implements ExternalSourceETARepository {
|
|
async addOrUpdateEtaFromExternalSource(eta: IEta): Promise<void> {
|
|
await this.addOrUpdateEta(eta);
|
|
}
|
|
|
|
async removeEtaIfExists(shuttleId: string, stopId: string): Promise<IEta | null> {
|
|
const index = this.etas.findIndex((e) => e.stopId === stopId && e.shuttleId === shuttleId);
|
|
if (index === -1) {
|
|
return null;
|
|
}
|
|
|
|
const removedEta = this.etas[index];
|
|
this.etas.splice(index, 1);
|
|
this.emit(ETARepositoryEvent.ETA_REMOVED, removedEta);
|
|
return removedEta;
|
|
}
|
|
}
|