add implementation for getShuttleById

This commit is contained in:
2025-01-07 20:47:37 -08:00
parent 77c2d88ba2
commit ae20bb9bb9

View File

@@ -109,7 +109,27 @@ export class ApiBasedRepository implements GetterRepository {
}
public async getShuttleById(shuttleId: string): Promise<IShuttle | null> {
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<[]> {