refactor(api-server): move agents SQL into db.agents/db.activity/db.approvals methods

Replace seven inline queryAll calls in routes-agents.ts with typed
domain methods. db.agents gains listAgentsForApi, listAgentsForStandup,
listExistingAgentsForHireCheck. db.tasks gains listTasksForStandup.
db.approvals gains listApprovalsForStandup and
listPendingHireApprovalPayloads. db.activity gains listRecentTaskComments
(safe on empty taskIds). All HTTP response projections stay identical.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 22:37:10 -04:00
1 parent efb9fdb8cc
commit 28296b3d5f
6 files changed
+213 -62

No files matched your search

+26
View File
@@ -33,5 +33,31 @@ export function buildActivityMethods(
taskId,
);
},
/**
* Returns the `limit` most recent task comments (author_name + body +
* createdAt) for a given set of task ids since `sinceIso`. Used by
* GET /api/agents/me/standup to build the "recent comments" feed.
*/
listRecentTaskComments(
taskIds: string[],
sinceIso: string,
limit: number,
): Array<{
id: string;
taskId: string;
authorName: string;
body: string;
createdAt: string;
}> {
if (taskIds.length === 0) return [];
const placeholders = taskIds.map(() => "?").join(",");
return readAll(
`select id, task_id as taskId, author_name as authorName, body, created_at as createdAt from task_comments where task_id in (${placeholders}) and created_at > ? order by created_at desc limit ?`,
...taskIds,
sinceIso,
limit,
);
},
};
}