[node] stop trying to optimize useless things like local database calls
This commit is contained in:
parent
a1d6b03ec9
commit
3cb4f4df51
12 changed files with 79 additions and 57 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue