MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / resolvePreferredOrganization

Function resolvePreferredOrganization

server/src/db/users-db.ts:205–218  ·  view source on GitHub ↗
(workosUserId: string)

Source from the content-addressed store, hash-verified

203 * Returns null if the user has no memberships.
204 */
205export async function resolvePreferredOrganization(workosUserId: string): Promise<string | null> {
206 const result = await query<{ workos_organization_id: string }>(
207 `SELECT om.workos_organization_id
208 FROM organization_memberships om
209 JOIN organizations o ON o.workos_organization_id = om.workos_organization_id
210 WHERE om.workos_user_id = $1
211 ORDER BY
212 CASE WHEN o.subscription_status = 'active' THEN 0 ELSE 1 END,
213 om.created_at DESC
214 LIMIT 1`,
215 [workosUserId]
216 );
217 return result.rows[0]?.workos_organization_id ?? null;
218}
219
220/**
221 * Backfill primary_organization_id for a user if not already set.

Callers 2

enrichUserWithMembershipFunction · 0.85
upsertMembershipFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected