summaryrefslogtreecommitdiff
path: root/nodejs/lib/contracts.js
diff options
context:
space:
mode:
authorJulien Dessaux2023-07-01 23:13:13 +0200
committerJulien Dessaux2023-07-01 23:13:13 +0200
commit36cc33f9e96a38ecea98ac8d26275b4828347d80 (patch)
tree653dcea7e656ec815fc0a1fa5664a6b89abccaa3 /nodejs/lib/contracts.js
parentFixed prepared statements (diff)
downloadspacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.tar.gz
spacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.tar.bz2
spacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.zip
Moved the nodejs agent to its own subfolder to make room for my haskell agent
Diffstat (limited to 'nodejs/lib/contracts.js')
-rw-r--r--nodejs/lib/contracts.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/nodejs/lib/contracts.js b/nodejs/lib/contracts.js
new file mode 100644
index 0000000..316e181
--- /dev/null
+++ b/nodejs/lib/contracts.js
@@ -0,0 +1,26 @@
+import * as api from './api.js';
+import * as dbShips from '../database/ships.js';
+
+export async function accept(ctx) {
+ return await api.send({endpoint: `/my/contracts/${ctx.contract}/accept`, method: 'POST'});
+}
+
+export async function contracts() {
+ return await api.send({endpoint: '/my/contracts'});
+}
+
+export async function deliver(ctx) {
+ const response = await api.send({ endpoint: `/my/contracts/${ctx.contract}/deliver`, method: 'POST', payload: {
+ shipSymbol: ctx.symbol,
+ tradeSymbol: ctx.good,
+ units: ctx.units,
+ }});
+ if (response.error !== undefined) {
+ throw response;
+ }
+ dbShips.setShipCargo(ctx.symbol, response.data.cargo);
+}
+
+export async function fulfill(ctx) {
+ return await api.send({ endpoint: `/my/contracts/${ctx.contract}/fulfill`, method: 'POST'});
+}