From 28b3a695dce34b5adafb0139978de63271f75180 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 12 Jun 2023 23:40:07 +0200 Subject: Use the database cache for mining and contracting automations --- lib/contracts.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/contracts.js b/lib/contracts.js index abf32b3..316e181 100644 --- a/lib/contracts.js +++ b/lib/contracts.js @@ -1,4 +1,5 @@ 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'}); @@ -9,11 +10,15 @@ export async function contracts() { } export async function deliver(ctx) { - return await api.send({ endpoint: `/my/contracts/${ctx.contract}/deliver`, method: 'POST', payload: { + 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) { -- cgit v1.2.3