diff options
Diffstat (limited to '')
-rw-r--r-- | nodejs/database/contracts.js | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/nodejs/database/contracts.js b/nodejs/database/contracts.js index ac583de..d7f9aab 100644 --- a/nodejs/database/contracts.js +++ b/nodejs/database/contracts.js @@ -2,6 +2,7 @@ import db from './db.js'; const addContractStatement = db.prepare(`INSERT INTO contracts(data) VALUES (json(?));`); const getContractStatement = db.prepare(`SELECT data FROM contracts WHERE data->>'id' = ?;`); +const getContractsStatement = db.prepare(`SELECT data FROM contracts WHERE data->>'fulfilled' = false;`); const updateContractStatement = db.prepare(`UPDATE contracts SET data = json(:data) WHERE data->>'id' = :id;`); export function getContract(id) { @@ -12,6 +13,11 @@ export function getContract(id) { return JSON.parse(data.data); } +export function getContracts() { + const data = getContractsStatement.all(); + return data.map(contractData => JSON.parse(contractData.data)); +} + export function setContract(data) { if (getContract(data.id) === null) { return addContractStatement.run(JSON.stringify(data)).lastInsertRowid; |