summaryrefslogtreecommitdiff
path: root/lib/systems.js
diff options
context:
space:
mode:
authorJulien Dessaux2023-05-29 23:25:09 +0200
committerJulien Dessaux2023-05-29 23:25:09 +0200
commitd79a4485a6b1a3ae6b647d94b45ee22a515441f2 (patch)
treeeccef4acf2a206fa0cfd74c783672287ae99a50b /lib/systems.js
parentRefactored the code to separate automation code from the lib handling the api (diff)
downloadspacetraders-d79a4485a6b1a3ae6b647d94b45ee22a515441f2.tar.gz
spacetraders-d79a4485a6b1a3ae6b647d94b45ee22a515441f2.tar.bz2
spacetraders-d79a4485a6b1a3ae6b647d94b45ee22a515441f2.zip
Many new api calls
Diffstat (limited to '')
-rw-r--r--lib/systems.js19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/systems.js b/lib/systems.js
index ad354e4..4b480de 100644
--- a/lib/systems.js
+++ b/lib/systems.js
@@ -3,18 +3,18 @@ import * as db from '../database/systems.js';
// Retrieves a list of waypoints that have a specific ctx.trait like a SHIPYARD or a MARKETPLACE in the system ctx.symbol
export async function trait(ctx) {
- const s = await getSystem(ctx);
+ const s = await system(ctx);
return s.filter(s => s.traits.some(t => t.symbol === ctx.trait));
}
// Retrieves a list of waypoints that have a specific ctx.type like ASTEROID_FIELD in the system ctx.symbol
export async function type(ctx, response) {
- const s = await getSystem(ctx);
+ const s = await system(ctx);
return s.filter(s => s.type === ctx.type);
}
// Retrieves the system's information for ctx.symbol and cache it in the database
-async function getSystem(ctx) {
+export async function system(ctx) {
let s = db.getSystem(ctx.symbol);
if (s === null) {
const response = await api.send({endpoint: `/systems/${ctx.symbol}/waypoints?limit=20&page=1`});
@@ -34,3 +34,16 @@ async function getSystem(ctx) {
}
return s;
}
+
+export async function systems(ctx) {
+ const response = await api.send({endpoint: `/systems?limit=20&page=1`});
+ // TODO pagination
+ return response;
+}
+
+// Retrieves a shipyard's information for ctx.symbol
+export async function shipyard(ctx) {
+ const systemSymbol = ctx.symbol.match(/([^-]+-[^-]+)/)[1]; // TODO generalise this extraction
+ console.log(systemSymbol);
+ return await api.send({endpoint: `/systems/${systemSymbol}/waypoints/${ctx.symbol}/shipyard`});
+}