summaryrefslogtreecommitdiff
path: root/nodejs/lib
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-17 01:23:40 +0100
committerJulien Dessaux2024-03-17 01:27:35 +0100
commit0377c99a549bed141d1371577a8d0b10dd09f40d (patch)
tree05a764e592f15f0a5521d2e4c77264973dde43cf /nodejs/lib
parent[javascript] Rework the contracting loop following the asteroids changes (diff)
downloadspacetraders-0377c99a549bed141d1371577a8d0b10dd09f40d.tar.gz
spacetraders-0377c99a549bed141d1371577a8d0b10dd09f40d.tar.bz2
spacetraders-0377c99a549bed141d1371577a8d0b10dd09f40d.zip
[javascript] refactoring
Diffstat (limited to '')
-rw-r--r--nodejs/lib/systems.js4
-rw-r--r--nodejs/lib/utils.js (renamed from nodejs/automation/utils.js)2
2 files changed, 4 insertions, 2 deletions
diff --git a/nodejs/lib/systems.js b/nodejs/lib/systems.js
index e03da6c..fefa5cd 100644
--- a/nodejs/lib/systems.js
+++ b/nodejs/lib/systems.js
@@ -1,9 +1,11 @@
import * as api from './api.js';
import * as db from '../database/systems.js';
+import * as utils from './utils.js';
+
// Retrieves a shipyard's information for ctx.symbol
export async function shipyard(ctx) {
- const systemSymbol = ctx.symbol.match(/([^-]+-[^-]+)/)[1]; // TODO generalise this extraction
+ const systemSymbol = utils.systemFromWaypoint(ctx.symbol);
console.log(systemSymbol);
return await api.send({endpoint: `/systems/${systemSymbol}/waypoints/${ctx.symbol}/shipyard`});
}
diff --git a/nodejs/automation/utils.js b/nodejs/lib/utils.js
index 01ce1ad..1d2e451 100644
--- a/nodejs/automation/utils.js
+++ b/nodejs/lib/utils.js
@@ -1,3 +1,3 @@
-export function waypointToSystem(waypoint) {
+export function systemFromWaypoint(waypoint) {
return waypoint.split('-').slice(0,2).join('-');
}