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

+40
View File
@@ -190,6 +190,46 @@ export function buildTaskCrudMethods(
);
},
/**
* Returns the slim task projection (id, title, status, priority) for a
* single assignee, ordered by created_at desc. Used by the alternate
* me/standup builder in routes-agents-standup.ts.
*/
listAssigneeTasksForStandup(
companyId: string,
agentId: string,
): Array<{ id: string; title: string; status: string; priority: string }> {
return readAll(
"select id, title, status, priority from tasks where company_id = ? and assignee_agent_id = ? order by created_at desc",
companyId,
agentId,
);
},
/**
* Returns the slim task projection for a set of assignees. Safe on
* an empty assignee list (returns []). Used by the alternate
* me/standup builder to fetch reports' tasks in one query.
*/
listTasksForAssignees(
companyId: string,
assigneeIds: string[],
): Array<{
id: string;
title: string;
status: string;
priority: string;
assigneeAgentId: string;
}> {
if (assigneeIds.length === 0) return [];
const placeholders = assigneeIds.map(() => "?").join(",");
return readAll(
`select id, title, status, priority, assignee_agent_id as assigneeAgentId from tasks where company_id = ? and assignee_agent_id in (${placeholders}) order by created_at desc`,
companyId,
...assigneeIds,
);
},
/**
* Returns the slim task projection used by the me/standup aggregation.
* Ordered by created_at desc.