refactor(api-server): move approvals SQL into db.approvals domain methods
Replace the ad-hoc getApproval helper and the filterable list query in routes-approvals.ts with db.approvals methods. Add findApprovalById (non-throwing lookup returning null) and listApprovalsForApi (accepts requestedByAgentId / relatedTaskId / statuses filters and builds the prepared statement inside the domain layer).
This commit is contained in:
1 parent
28296b3d5f
commit
4342cf3e2f
3 files changed
+26
-30
No files matched your search
@@ -23,6 +23,20 @@ export function buildApprovalMethods(
|
||||
return row;
|
||||
},
|
||||
|
||||
/**
|
||||
* Non-throwing lookup by id. Returns null when the approval does not
|
||||
* exist. Used by approval routes that need to branch on 404 rather
|
||||
* than catching an exception.
|
||||
*/
|
||||
findApprovalById(id: string): (ApprovalRecord & { payloadJson: string | null; relatedAgentId: string | null }) | null {
|
||||
const row = getDb()
|
||||
.prepare(
|
||||
"select id, company_id as companyId, related_task_id as relatedTaskId, requested_by_agent_id as requestedByAgentId, related_agent_id as relatedAgentId, type, payload_summary as payloadSummary, impact_summary as impactSummary, payload_json as payloadJson, decision_note as decisionNote, state, created_at as createdAt, updated_at as updatedAt from approvals where id = ?",
|
||||
)
|
||||
.get(id) as (ApprovalRecord & { payloadJson: string | null; relatedAgentId: string | null }) | undefined;
|
||||
return row ?? null;
|
||||
},
|
||||
|
||||
requestApproval(input: {
|
||||
companyId: string;
|
||||
relatedTaskId?: string | null;
|
||||
|
||||
Reference in new issue
Block a user