1
0
Fork 0

[javascript] refactoring

This commit is contained in:
Julien Dessaux 2024-03-17 01:23:40 +01:00
parent 01e3f05ea0
commit 0377c99a54
Signed by: adyxax
GPG key ID: F92E51B86E07177E
3 changed files with 6 additions and 4 deletions

View file

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

3
nodejs/lib/utils.js Normal file
View file

@ -0,0 +1,3 @@
export function systemFromWaypoint(waypoint) {
return waypoint.split('-').slice(0,2).join('-');
}