[javascript] Track credits on contract fulfillment
This commit is contained in:
parent
378b5a5ffb
commit
6cf84fe67f
2 changed files with 7 additions and 0 deletions
|
@ -2,6 +2,7 @@ import db from './db.js';
|
||||||
|
|
||||||
const addAgentStatement = db.prepare(`INSERT INTO agents(data) VALUES (json(?));`);
|
const addAgentStatement = db.prepare(`INSERT INTO agents(data) VALUES (json(?));`);
|
||||||
const getAgentStatement = db.prepare(`SELECT data FROM agents;`);
|
const getAgentStatement = db.prepare(`SELECT data FROM agents;`);
|
||||||
|
const setAgentStatement = db.prepare(`UPDATE agents SET data = json(?);`);
|
||||||
|
|
||||||
export function addAgent(agent) {
|
export function addAgent(agent) {
|
||||||
return addAgentStatement.run(JSON.stringify(agent)).lastInsertRowid;
|
return addAgentStatement.run(JSON.stringify(agent)).lastInsertRowid;
|
||||||
|
@ -14,3 +15,7 @@ export function getAgent() {
|
||||||
}
|
}
|
||||||
return JSON.parse(data.data);
|
return JSON.parse(data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setAgent(agent) {
|
||||||
|
return setAgentStatement.run(JSON.stringify(agent)).changes;
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as dbAgents from '../database/agents.js';
|
||||||
import * as dbContracts from '../database/contracts.js';
|
import * as dbContracts from '../database/contracts.js';
|
||||||
import * as api from './api.js';
|
import * as api from './api.js';
|
||||||
import * as dbShips from '../database/ships.js';
|
import * as dbShips from '../database/ships.js';
|
||||||
|
@ -62,5 +63,6 @@ export async function fulfill(ctx) {
|
||||||
api.debugLog(response);
|
api.debugLog(response);
|
||||||
throw response;
|
throw response;
|
||||||
}
|
}
|
||||||
|
dbAgents.setAgent(response.data.agent);
|
||||||
dbContracts.setContract(response.data.contract);
|
dbContracts.setContract(response.data.contract);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue