refactor(db): add findAgent/findConnector; wrap linkManyTasksToApproval in tx; collapse saveAgent IIFEs (P1-28, P1-29)

This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 23:02:13 -04:00
1 parent a05885c0ff
commit 821855931d
5 files changed
+38 -30

No files matched your search

+11
View File
@@ -71,6 +71,17 @@ export function buildEntityCrudMethods(
return row;
},
findAgent(id: string): AgentRecord | null {
const row = getDb()
.prepare(
"select id, company_id as companyId, name, role, title, department, status, reports_to as reportsTo, connector_id as connectorId, workspace_id as workspaceId, model, capabilities, budget_monthly_usd as budgetMonthlyUsd, spent_monthly_usd as spentMonthlyUsd, metadata_json as metadataJson, heartbeat_enabled as heartbeatEnabled, heartbeat_interval_sec as heartbeatIntervalSec, last_heartbeat_at as lastHeartbeatAt, created_at as createdAt, updated_at as updatedAt from agents where id = ?",
)
.get(id) as AgentRecord | undefined;
if (!row) return null;
row.heartbeatEnabled = Boolean(row.heartbeatEnabled);
return row;
},
/**
* Returns all goals for a company. Used by GET /api/companies/:id/goals.
*/