(memberships: { status: string; role?: { slug: string } }[])
| 14 | * or null if no active memberships exist. |
| 15 | */ |
| 16 | export function resolveUserRole(memberships: { status: string; role?: { slug: string } }[]): string | null { |
| 17 | let best = -1; |
| 18 | let bestSlug: string | null = null; |
| 19 | for (const m of memberships) { |
| 20 | if (m.status !== 'active') continue; |
| 21 | const slug = m.role?.slug || 'member'; |
| 22 | const priority = ROLE_PRIORITY[slug]; |
| 23 | if (priority === undefined) { |
| 24 | logger.warn({ slug }, 'Unknown organization role slug encountered'); |
| 25 | continue; |
| 26 | } |
| 27 | if (priority > best) { |
| 28 | best = priority; |
| 29 | bestSlug = slug; |
| 30 | } |
| 31 | } |
| 32 | return bestSlug; |
| 33 | } |
no test coverage detected