add event_date column to event_knowledge and event_predictions tables; update related logic in admin panel and augorWorker

This commit is contained in:
ImBenji
2026-04-23 14:01:02 +01:00
parent 29c6cdc6c3
commit 7830ca7221
7 changed files with 1077 additions and 177 deletions
+51
View File
@@ -307,6 +307,57 @@ async function adminRoutes(fastify) {
return { total, rows };
});
// intelligence graph — nodes + edges from company_relationships
fastify.get('/admin/api/intelligence/graph', async (request, reply) => {
if (!checkAuth(request, reply)) return;
const idb = getIntelligenceDb();
if (!idb) return { nodes: [], edges: [] };
const edges = idb.prepare(`SELECT * FROM company_relationships`).all();
const trackedIds = new Set();
for (const e of edges) {
trackedIds.add(e.from_company_id);
if (e.to_company_id) trackedIds.add(e.to_company_id);
}
const allTracked = idb.prepare(`SELECT id, name, ticker FROM tracked_companies`).all();
// untracked entities — appear only as to_entity with no to_company_id
const untrackedSeen = new Set();
for (const e of edges) {
if (!e.to_company_id && e.to_entity) untrackedSeen.add(e.to_entity);
}
const nodes = [
...allTracked
.filter(c => trackedIds.has(c.id))
.map(c => ({ id: c.id, name: c.name, ticker: c.ticker, tracked: true })),
...[...untrackedSeen].map(name => ({ id: null, name, ticker: null, tracked: false })),
];
return { nodes, edges };
});
// per-company facts for the graph sidebar
fastify.get('/admin/api/intelligence/facts/:company_id', async (request, reply) => {
if (!checkAuth(request, reply)) return;
const idb = getIntelligenceDb();
if (!idb) return [];
const companyId = parseInt(request.params.company_id, 10);
return idb.prepare(`
SELECT type, claim, confidence, confirmation_count
FROM company_facts
WHERE company_id = ?
ORDER BY confirmation_count DESC
LIMIT 10
`).all(companyId);
});
// raw sql console
fastify.post('/admin/api/sql', async (request, reply) => {
if (!checkAuth(request, reply)) return;