summaryrefslogtreecommitdiff
path: root/nodejs/lib/contracts.ts
diff options
context:
space:
mode:
Diffstat (limited to 'nodejs/lib/contracts.ts')
-rw-r--r--nodejs/lib/contracts.ts6
1 files changed, 5 insertions, 1 deletions
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> {
+ 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<Array<Contract>> {
}
export async function deliver(contract: Contract, ship: Ship): Promise<Contract> {
+ 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<Contract>
}
export async function fulfill(contract: Contract): Promise<Contract> {
+ 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) {