summaryrefslogtreecommitdiff
path: root/lib/agent.js
blob: bf27e859c8c8ad725958c8deddc0b780ff693ff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { registerAgent } from '../database/config.js';

// This function inits the database in case we have an already registered game
export function init(symbol, faction, token) {
	registerAgent(symbol, faction, token);
	// TODO ships
	// TODO contract
	// TODO agent
}

// This function registers then inits the database
export function register(symbol, faction) {
	fetch(
		'https://api.spacetraders.io/v2/register',
		{
			method: 'POST',
			headers: {
				'Content-Type': 'application/json',
			},
			body: JSON.stringify({
				symbol: symbol,
				faction: faction,
			}),
		})
		.then(response => response.json())
		.then(response => {
			console.log(JSON.stringify(response, null, 2));
			init(symbol, faction, response.data.token);
			// TODO ship
			// TODO contract
			// TODO agent
		})
		.catch(err => console.error(err));
}