[javascript] refactoring
This commit is contained in:
parent
01e3f05ea0
commit
0377c99a54
3 changed files with 6 additions and 4 deletions
|
@ -5,7 +5,7 @@ import * as api from '../lib/api.js';
|
||||||
import * as contracts from '../lib/contracts.js';
|
import * as contracts from '../lib/contracts.js';
|
||||||
import * as libShips from '../lib/ships.js';
|
import * as libShips from '../lib/ships.js';
|
||||||
import * as systems from '../lib/systems.js';
|
import * as systems from '../lib/systems.js';
|
||||||
import * as utils from './utils.js';
|
import * as utils from '../lib/utils.js';
|
||||||
|
|
||||||
export async function init() {
|
export async function init() {
|
||||||
const cs = dbContracts.getContracts();
|
const cs = dbContracts.getContracts();
|
||||||
|
@ -14,7 +14,7 @@ export async function init() {
|
||||||
|
|
||||||
async function run(contract) {
|
async function run(contract) {
|
||||||
await contracts.accept({id: contract.id});
|
await contracts.accept({id: contract.id});
|
||||||
const contractSystem = utils.waypointToSystem(contract.terms.deliver[0].destinationSymbol);
|
const contractSystem = utils.systemFromWaypoint(contract.terms.deliver[0].destinationSymbol);
|
||||||
let ships = dbShips.getShipsAt(contractSystem);
|
let ships = dbShips.getShipsAt(contractSystem);
|
||||||
ships = ships.filter(ship => ship.registration.role !== 'SATELLITE'); // filter out probes
|
ships = ships.filter(ship => ship.registration.role !== 'SATELLITE'); // filter out probes
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import * as api from './api.js';
|
import * as api from './api.js';
|
||||||
import * as db from '../database/systems.js';
|
import * as db from '../database/systems.js';
|
||||||
|
import * as utils from './utils.js';
|
||||||
|
|
||||||
|
|
||||||
// Retrieves a shipyard's information for ctx.symbol
|
// Retrieves a shipyard's information for ctx.symbol
|
||||||
export async function shipyard(ctx) {
|
export async function shipyard(ctx) {
|
||||||
const systemSymbol = ctx.symbol.match(/([^-]+-[^-]+)/)[1]; // TODO generalise this extraction
|
const systemSymbol = utils.systemFromWaypoint(ctx.symbol);
|
||||||
console.log(systemSymbol);
|
console.log(systemSymbol);
|
||||||
return await api.send({endpoint: `/systems/${systemSymbol}/waypoints/${ctx.symbol}/shipyard`});
|
return await api.send({endpoint: `/systems/${systemSymbol}/waypoints/${ctx.symbol}/shipyard`});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export function waypointToSystem(waypoint) {
|
export function systemFromWaypoint(waypoint) {
|
||||||
return waypoint.split('-').slice(0,2).join('-');
|
return waypoint.split('-').slice(0,2).join('-');
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue