MCPcopy Index your code
hub / github.com/simstudioai/sim / listWorkflowsForUser

Function listWorkflowsForUser

apps/sim/lib/workflows/queries.ts:73–101  ·  view source on GitHub ↗
({
  userId,
  workspaceId,
  scope,
}: {
  userId: string
  workspaceId?: string
  scope: WorkflowListScope
})

Source from the content-addressed store, hash-verified

71 * workflows across every workspace the user has permissions on.
72 */
73export 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}

Callers 2

prefetchWorkspaceSidebarFunction · 0.90
route.tsFile · 0.90

Calls 3

scopeConditionFunction · 0.85
eqFunction · 0.50

Tested by

no test coverage detected