refactoring
This commit is contained in:
@@ -20,10 +20,19 @@ class OrganizationModel extends Model
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
// Получить организации конкретного пользователя
|
||||
public function getUserOrganizations(int $userId)
|
||||
public function getUserOrganizations(int $userId): array
|
||||
{
|
||||
// TODO: Здесь мы будем делать JOIN с таблицей organization_users
|
||||
// Пока упрощенная версия для владельца
|
||||
return $this->where('owner_id', $userId)->findAll();
|
||||
$db = $this->db();
|
||||
$builder = $db->newQuery();
|
||||
|
||||
return $builder->select('o.*, ou.role, ou.status as membership_status, ou.joined_at')
|
||||
->from('organizations o')
|
||||
->join('organization_users ou', 'ou.organization_id = o.id', 'inner')
|
||||
->where('ou.user_id', $userId)
|
||||
->where('ou.status', 'active')
|
||||
->where('o.deleted_at', null)
|
||||
->orderBy('ou.joined_at', 'ASC')
|
||||
->get()
|
||||
->getResultArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user