diff options
Diffstat (limited to 'nodejs/lib')
-rw-r--r-- | nodejs/lib/systems.js | 4 | ||||
-rw-r--r-- | nodejs/lib/utils.js | 3 |
2 files changed, 6 insertions, 1 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/lib/utils.js b/nodejs/lib/utils.js new file mode 100644 index 0000000..1d2e451 --- /dev/null +++ b/nodejs/lib/utils.js @@ -0,0 +1,3 @@ +export function systemFromWaypoint(waypoint) { + return waypoint.split('-').slice(0,2).join('-'); +} |