mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add implementation for getShuttleById
This commit is contained in:
@@ -109,7 +109,27 @@ export class ApiBasedRepository implements GetterRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getShuttleById(shuttleId: string): Promise<IShuttle | null> {
|
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<[]> {
|
public async getShuttlesByRouteId(routeId: string): Promise<[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user