diff options
author | Julien Dessaux | 2024-04-06 10:55:11 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-04-07 23:01:52 +0200 |
commit | eeaa64b5ed54cee8f4ffc85f96178e9799c1a8ac (patch) | |
tree | 4c9ebcfd01773bb6c34e66e1325cf40739dae17f /nodejs/lib/systems.ts | |
parent | [node] Big Ships lib refactoring (diff) | |
download | spacetraders-eeaa64b5ed54cee8f4ffc85f96178e9799c1a8ac.tar.gz spacetraders-eeaa64b5ed54cee8f4ffc85f96178e9799c1a8ac.tar.bz2 spacetraders-eeaa64b5ed54cee8f4ffc85f96178e9799c1a8ac.zip |
[node] waypoints usage refactoring
Diffstat (limited to '')
-rw-r--r-- | nodejs/lib/systems.ts | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/nodejs/lib/systems.ts b/nodejs/lib/systems.ts index 97aa6e3..d4b3be5 100644 --- a/nodejs/lib/systems.ts +++ b/nodejs/lib/systems.ts @@ -8,15 +8,15 @@ import * as dbSystems from '../database/systems.ts'; import { Market, System, - Waypoint + Waypoint, } from './types.ts' import { systemFromWaypoint } from './utils.ts'; -export async function market(waypointSymbol: string): Promise<Market> { - const data = dbMarkets.getMarketAtWaypoint(waypointSymbol); +export async function market(waypoint: Waypoint): Promise<Market> { + const data = dbMarkets.getMarketAtWaypoint(waypoint.symbol); if (data) { return data; } - const systemSymbol = systemFromWaypoint(waypointSymbol); - let response = await send<Market>({endpoint: `/systems/${systemSymbol}/waypoints/${waypointSymbol}/market`}); + const systemSymbol = systemFromWaypoint(waypoint.symbol); + let response = await send<Market>({endpoint: `/systems/${systemSymbol}/waypoints/${waypoint.symbol}/market`}); if (response.error) { debugLog(response); throw response; @@ -55,6 +55,12 @@ export async function type(system: string, typeSymbol: string): Promise<Array<Wa return ws.filter(s => s.type === typeSymbol); } +export async function waypoint(waypointSymbol: string): Promise<Waypoint> { + const systemSymbol = systemFromWaypoint(waypointSymbol); + const w = await waypoints(systemSymbol); + return w.filter(w => w.symbol === waypointSymbol)[0]; +} + export async function waypoints(systemSymbol: string): Promise<Array<Waypoint>> { const s = await system(systemSymbol); const updated = dbSystems.getSystemUpdated(systemSymbol); |