summaryrefslogtreecommitdiff
path: root/nodejs/automation/init.js
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-27 15:20:14 +0100
committerJulien Dessaux2024-03-27 15:21:37 +0100
commita1d6b03ec98abbc073b5b73b631da6ea3eae4eb9 (patch)
tree1566c60bf1155e62821d9561ba1cc998b04b8ea5 /nodejs/automation/init.js
parent[all] fixed erroneous contracts index (diff)
downloadspacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.tar.gz
spacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.tar.bz2
spacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.zip
[node] finished the great typescript rewrite
Diffstat (limited to 'nodejs/automation/init.js')
-rw-r--r--nodejs/automation/init.js39
1 files changed, 0 insertions, 39 deletions
diff --git a/nodejs/automation/init.js b/nodejs/automation/init.js
deleted file mode 100644
index 93e5a70..0000000
--- a/nodejs/automation/init.js
+++ /dev/null
@@ -1,39 +0,0 @@
-import * as dbAgents from '../database/agents.js';
-import * as db from '../database/db.js';
-import * as dbContracts from '../database/contracts.js';
-import * as dbShips from '../database/ships.js';
-import * as dbTokens from '../database/tokens.js';
-import * as api from '../lib/api.js';
-import * as ships from '../lib/ships.js';
-
-const symbol = process.env.NODE_ENV === 'test' ? 'ADYXAX-0' : 'ADYXAX-TS';
-
-// This function registers then inits the database
-export async function init() {
- const response = await fetch('https://api.spacetraders.io/v2/register', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- symbol: symbol,
- faction: "COSMIC",
- }),
- });
- const json = await response.json();
- if (json.error !== undefined) {
- switch(json.error?.code) {
- case 4111: // 4111 means the agent symbol has already been claimed so no server reset happened
- return;
- default:
- throw json;
- }
- }
- db.reset();
- dbAgents.addAgent(json.data.agent);
- dbContracts.setContract(json.data.contract);
- dbShips.setShip(json.data.ship);
- dbTokens.addToken(json.data.token);
- // Temporary fix to fetch the data on the startup probe
- ships.ships();
-}