1
0
Fork 0

[node] waypoints usage refactoring

This commit is contained in:
Julien Dessaux 2024-04-06 10:55:11 +02:00
parent 234770b611
commit eeaa64b5ed
Signed by: adyxax
GPG key ID: F92E51B86E07177E
5 changed files with 43 additions and 33 deletions

View file

@ -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);