summaryrefslogtreecommitdiff
path: root/nodejs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--nodejs/database/000_init.sql1
-rw-r--r--nodejs/lib/contracts.js9
2 files changed, 9 insertions, 1 deletions
diff --git a/nodejs/database/000_init.sql b/nodejs/database/000_init.sql
index 9c06622..67967b6 100644
--- a/nodejs/database/000_init.sql
+++ b/nodejs/database/000_init.sql
@@ -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'));
diff --git a/nodejs/lib/contracts.js b/nodejs/lib/contracts.js
index e4ba2ae..f73f297 100644
--- a/nodejs/lib/contracts.js
+++ b/nodejs/lib/contracts.js
@@ -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() {