()
| 579 | * Uses the local organization_memberships table (synced from WorkOS via webhooks). |
| 580 | */ |
| 581 | export async function buildAaoEmailToUserIdMap(): Promise<Map<string, string>> { |
| 582 | const pool = getPool(); |
| 583 | const aaoEmailToUserId = new Map<string, string>(); |
| 584 | const result = await pool.query<{ email: string; workos_user_id: string }>(` |
| 585 | SELECT DISTINCT email, workos_user_id |
| 586 | FROM organization_memberships |
| 587 | WHERE email IS NOT NULL |
| 588 | `); |
| 589 | for (const row of result.rows) { |
| 590 | aaoEmailToUserId.set(row.email.toLowerCase(), row.workos_user_id); |
| 591 | } |
| 592 | return aaoEmailToUserId; |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Check if a user should be assigned to an organization based on their email domain. |
no test coverage detected