refactor(api-server): move agents-standup SQL into db domain methods

Replace the six inline queryAll calls in routes-agents-standup.ts with
typed domain methods: db.agents gains listDirectReportsForStandup and
listReportStatusesForStandup (LEFT JOIN aggregation), db.tasks gains
listAssigneeTasksForStandup and listTasksForAssignees (safe on empty
assignee list), db.approvals gains listAgentPendingApprovals and
listAgentResolvedApprovals. Shared listRecentTaskComments is reused.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 22:39:43 -04:00
1 parent 4342cf3e2f
commit 9874d825b6
5 files changed
+146 -94

No files matched your search

+44
View File
@@ -130,6 +130,50 @@ export function buildApprovalMethods(
getDb().prepare("delete from approvals where id = ? and company_id = ?").run(id, companyId);
},
/**
* Returns the requesting agent's pending approvals for standup
* aggregation (id, type, state, payloadSummary, decisionNote).
*/
listAgentPendingApprovals(
companyId: string,
agentId: string,
): Array<{
id: string;
type: string;
state: string;
payloadSummary: string | null;
decisionNote: string | null;
}> {
return readAll(
"select id, type, state, payload_summary as payloadSummary, decision_note as decisionNote from approvals where company_id = ? and requested_by_agent_id = ? and state = 'pending' order by created_at desc",
companyId,
agentId,
);
},
/**
* Returns up to `limit` of the requesting agent's resolved approvals
* for standup aggregation (state != 'pending').
*/
listAgentResolvedApprovals(
companyId: string,
agentId: string,
limit = 5,
): Array<{
id: string;
type: string;
state: string;
payloadSummary: string | null;
decisionNote: string | null;
}> {
return readAll(
"select id, type, state, payload_summary as payloadSummary, decision_note as decisionNote from approvals where company_id = ? and requested_by_agent_id = ? and state != 'pending' order by created_at desc limit ?",
companyId,
agentId,
limit,
);
},
/**
* Returns the slim approval projection used by
* GET /api/agents/me/standup. Ordered by created_at desc.