1
0
Fork 0

Moved the nodejs agent to its own subfolder to make room for my haskell agent

This commit is contained in:
Julien Dessaux 2023-07-01 23:13:13 +02:00
parent 0bc0df0891
commit 36cc33f9e9
Signed by: adyxax
GPG key ID: F92E51B86E07177E
22 changed files with 0 additions and 0 deletions

26
nodejs/lib/contracts.js Normal file
View file

@ -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'});
}