({
userId,
workspaceId,
scope,
}: {
userId: string
workspaceId?: string
scope: WorkflowListScope
})
| 71 | * workflows across every workspace the user has permissions on. |
| 72 | */ |
| 73 | export async function listWorkflowsForUser({ |
| 74 | userId, |
| 75 | workspaceId, |
| 76 | scope, |
| 77 | }: { |
| 78 | userId: string |
| 79 | workspaceId?: string |
| 80 | scope: WorkflowListScope |
| 81 | }): Promise<WorkflowListItem[]> { |
| 82 | if (workspaceId) { |
| 83 | const rows = await db |
| 84 | .select(listColumns) |
| 85 | .from(workflow) |
| 86 | .where(scopeCondition(scope, eq(workflow.workspaceId, workspaceId))) |
| 87 | .orderBy(...orderByClause) |
| 88 | return rows.map(toListItem) |
| 89 | } |
| 90 | |
| 91 | const accessibleRows = await listAccessibleWorkspaceRowsForUser(userId, 'all') |
| 92 | const workspaceIds = accessibleRows.map((row) => row.workspace.id) |
| 93 | if (workspaceIds.length === 0) return [] |
| 94 | |
| 95 | const rows = await db |
| 96 | .select(listColumns) |
| 97 | .from(workflow) |
| 98 | .where(scopeCondition(scope, inArray(workflow.workspaceId, workspaceIds))) |
| 99 | .orderBy(...orderByClause) |
| 100 | return rows.map(toListItem) |
| 101 | } |
no test coverage detected