getAdminOrgs method

Future<List<OrganizationModel>> getAdminOrgs()

Orgs where the caller is an owner or admin. Used by the first-connection admin-onboarding wizard (Plan 49) to decide whether the wizard runs and which orgs the user can pick from.

Implementation

Future<List<OrganizationModel>> getAdminOrgs() async {
  final memberRows = await _client
      .from('org_members')
      .select('org_id, role')
      .eq('user_id', _userId)
      .inFilter('role', ['owner', 'admin']);
  final orgIds = (memberRows as List<dynamic>)
      .map((row) => (row as Map<String, dynamic>)['org_id'] as String)
      .toList();
  if (orgIds.isEmpty) return [];
  final response = await _client
      .from('organizations')
      .select()
      .inFilter('id', orgIds)
      .order('name');
  return (response as List<dynamic>)
      .map((row) => OrganizationModel.fromJson(row as Map<String, dynamic>))
      .toList();
}