From 234770b611df32178382b557df396db220070a7f Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Fri, 5 Apr 2024 00:42:30 +0200 Subject: [node] Big Ships lib refactoring --- nodejs/lib/systems.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'nodejs/lib/systems.ts') diff --git a/nodejs/lib/systems.ts b/nodejs/lib/systems.ts index dc938bb..97aa6e3 100644 --- a/nodejs/lib/systems.ts +++ b/nodejs/lib/systems.ts @@ -1,18 +1,24 @@ -import * as api from './api.ts'; +import { + debugLog, + send, + sendPaginated, +} from './api.ts'; import * as dbMarkets from '../database/markets.ts'; -import * as dbShips from '../database/ships.ts'; import * as dbSystems from '../database/systems.ts'; -import { Market } from '../model/market.ts' -import { System, Waypoint } from '../model/system.ts' -import * as utils from './utils.ts'; +import { + Market, + System, + Waypoint +} from './types.ts' +import { systemFromWaypoint } from './utils.ts'; export async function market(waypointSymbol: string): Promise { const data = dbMarkets.getMarketAtWaypoint(waypointSymbol); if (data) { return data; } - const systemSymbol = utils.systemFromWaypoint(waypointSymbol); - let response = await api.send({endpoint: `/systems/${systemSymbol}/waypoints/${waypointSymbol}/market`}); + const systemSymbol = systemFromWaypoint(waypointSymbol); + let response = await send({endpoint: `/systems/${systemSymbol}/waypoints/${waypointSymbol}/market`}); if (response.error) { - api.debugLog(response); + debugLog(response); throw response; } dbMarkets.setMarket(response.data); @@ -21,16 +27,16 @@ export async function market(waypointSymbol: string): Promise { //export async function shipyard(waypoint: string): Promise { // // TODO database caching -// const systemSymbol = utils.systemFromWaypoint(waypoint); -// return await api.send({endpoint: `/systems/${systemSymbol}/waypoints/${waypoint}/shipyard`}); +// const systemSymbol = systemFromWaypoint(waypoint); +// return await send({endpoint: `/systems/${systemSymbol}/waypoints/${waypoint}/shipyard`}); //} export async function system(symbol: string): Promise { let data = dbSystems.getSystem(symbol); if (data) { return data; } - const response = await api.send({endpoint: `/systems/${symbol}`}); + const response = await send({endpoint: `/systems/${symbol}`}); if (response.error) { - api.debugLog(response); + debugLog(response); throw response; } dbSystems.setSystem(response.data); @@ -54,7 +60,7 @@ export async function waypoints(systemSymbol: string): Promise> const updated = dbSystems.getSystemUpdated(systemSymbol); // TODO handle uncharted systems if (updated) return s.waypoints; - const waypoints = await api.sendPaginated({endpoint: `/systems/${systemSymbol}/waypoints`}); + const waypoints = await sendPaginated({endpoint: `/systems/${systemSymbol}/waypoints`}); dbSystems.setSystemWaypoints(systemSymbol, waypoints); return waypoints; } -- cgit v1.2.3