From 6cf84fe67f3a6232753a97afc8a41a07e759d1b0 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Fri, 20 Oct 2023 00:17:31 +0200 Subject: [javascript] Track credits on contract fulfillment --- nodejs/database/agents.js | 5 +++++ nodejs/lib/contracts.js | 2 ++ 2 files changed, 7 insertions(+) (limited to 'nodejs') diff --git a/nodejs/database/agents.js b/nodejs/database/agents.js index 4dd7f4b..8b7203b 100644 --- a/nodejs/database/agents.js +++ b/nodejs/database/agents.js @@ -2,6 +2,7 @@ import db from './db.js'; const addAgentStatement = db.prepare(`INSERT INTO agents(data) VALUES (json(?));`); const getAgentStatement = db.prepare(`SELECT data FROM agents;`); +const setAgentStatement = db.prepare(`UPDATE agents SET data = json(?);`); export function addAgent(agent) { return addAgentStatement.run(JSON.stringify(agent)).lastInsertRowid; @@ -14,3 +15,7 @@ export function getAgent() { } return JSON.parse(data.data); } + +export function setAgent(agent) { + return setAgentStatement.run(JSON.stringify(agent)).changes; +} diff --git a/nodejs/lib/contracts.js b/nodejs/lib/contracts.js index a009889..9718f99 100644 --- a/nodejs/lib/contracts.js +++ b/nodejs/lib/contracts.js @@ -1,3 +1,4 @@ +import * as dbAgents from '../database/agents.js'; import * as dbContracts from '../database/contracts.js'; import * as api from './api.js'; import * as dbShips from '../database/ships.js'; @@ -62,5 +63,6 @@ export async function fulfill(ctx) { api.debugLog(response); throw response; } + dbAgents.setAgent(response.data.agent); dbContracts.setContract(response.data.contract); } -- cgit v1.2.3