getMyOrganizations method

Future<List<OrganizationModel>> getMyOrganizations()

Implementation

Future<List<OrganizationModel>> getMyOrganizations() async {
  final memberRows = await _client
      .from('org_members')
      .select('org_id')
      .eq('user_id', _userId);
  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();
}