[javascript] improved contract lib
This commit is contained in:
parent
14f81bcc1b
commit
4c1a5fdfe1
2 changed files with 9 additions and 1 deletions
|
@ -14,3 +14,4 @@ CREATE TABLE contracts (
|
|||
data TEXT NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX contracts_data_id ON contracts (json_extract(data, '$.id'));
|
||||
CREATE UNIQUE INDEX contracts_data_fulfilled ON contracts (json_extract(data, '$.fulfilled'));
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
import * as dbContracts from '../database/contracts.js';
|
||||
import * as api from './api.js';
|
||||
import * as dbShips from '../database/ships.js';
|
||||
import * as libShips from '../lib/ships.js';
|
||||
|
||||
export async function accept(ctx) {
|
||||
return await api.send({endpoint: `/my/contracts/${ctx.contract}/accept`, method: 'POST'});
|
||||
const contract = dbContracts.getContract(ctx.id);
|
||||
if (contract.accepted) {
|
||||
return;
|
||||
}
|
||||
await api.send({endpoint: `/my/contracts/${ctx.id}/accept`, method: 'POST'});
|
||||
contract.accepted = true;
|
||||
dbContracts.setContract(contract);
|
||||
}
|
||||
|
||||
export async function contracts() {
|
||||
|
|
Loading…
Add table
Reference in a new issue