From 3cb4f4df51059919b292fefb5f7a3e1ad99c9a91 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 28 Mar 2024 12:11:36 +0100 Subject: [node] stop trying to optimize useless things like local database calls --- nodejs/lib/contracts.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'nodejs/lib/contracts.ts') diff --git a/nodejs/lib/contracts.ts b/nodejs/lib/contracts.ts index 0adb5f6..54347cb 100644 --- a/nodejs/lib/contracts.ts +++ b/nodejs/lib/contracts.ts @@ -10,6 +10,7 @@ import * as dbShips from '../database/ships.ts'; import * as libShips from '../lib/ships.ts'; export async function accept(contract: Contract): Promise { + contract = dbContracts.getContract(contract.id); if (contract.accepted) return contract; const response = await api.send<{agent: Agent, contract: Contract, type: ''}>({endpoint: `/my/contracts/${contract.id}/accept`, method: 'POST'}); if (response.error) { @@ -28,13 +29,15 @@ export async function contracts(): Promise> { } export async function deliver(contract: Contract, ship: Ship): Promise { + contract = dbContracts.getContract(contract.id); + ship = dbShips.getShip(ship.symbol); if (contract.terms.deliver[0].unitsRequired >= contract.terms.deliver[0].unitsFulfilled) { return await fulfill(contract); } const tradeSymbol = contract.terms.deliver[0].tradeSymbol; let units = 0; ship.cargo.inventory.forEach(i => {if (i.symbol === tradeSymbol) units = i.units; }); - ship = await libShips.dock(ship); // we need to be docked to deliver + await libShips.dock(ship); // we need to be docked to deliver const response = await api.send<{contract: Contract, cargo: Cargo}>({ endpoint: `/my/contracts/${contract.id}/deliver`, method: 'POST', payload: { shipSymbol: ship.symbol, tradeSymbol: tradeSymbol, @@ -58,6 +61,7 @@ export async function deliver(contract: Contract, ship: Ship): Promise } export async function fulfill(contract: Contract): Promise { + contract = dbContracts.getContract(contract.id); if (contract.fulfilled) return contract; const response = await api.send<{agent: Agent, contract: Contract}>({ endpoint: `/my/contracts/${contract.id}/fulfill`, method: 'POST'}); if (response.error) { -- cgit v1.2.3