diff --git a/src/repositories/ApiBasedRepository.ts b/src/repositories/ApiBasedRepository.ts index 3b49aac..878c2b4 100644 --- a/src/repositories/ApiBasedRepository.ts +++ b/src/repositories/ApiBasedRepository.ts @@ -109,7 +109,27 @@ export class ApiBasedRepository implements GetterRepository { } public async getShuttleById(shuttleId: string): Promise { - return Promise.resolve(null); + if (!this.cache.shuttleByShuttleId) return null; + let shuttle = this.cache.shuttleByShuttleId[shuttleId]; + if (!shuttle) return null; + + // If the shuttle exists and not TTL, then return it + + const now = Date.now(); + if ( + shuttle.millisecondsSinceEpoch !== undefined + && this.ttls.shuttleByShuttleId !== undefined + && now - shuttle.millisecondsSinceEpoch > this.ttls.shuttleByShuttleId + ) { + return shuttle; + } + + // Otherwise, call getShuttlesBySystemId to update the data + await this.getShuttlesBySystemId(shuttle.systemId); + + shuttle = this.cache.shuttleByShuttleId[shuttleId]; + if (!shuttle) return null; + return shuttle; } public async getShuttlesByRouteId(routeId: string): Promise<[]> {