summaryrefslogtreecommitdiff
path: root/app/serializers/switchboard_entry_serializer.rb
blob: 5d76e16dd5bba880aacace421fb23a24add97f37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class SwitchboardEntrySerializer < ActiveModel::Serializer
  attributes :id, :name, :path_to_user, :avatar_src, :callstate, :switchable

  has_one :sip_account, embed: :ids
  has_one :switchboard, embed: :ids

  def path_to_user
    if object.sip_account && object.sip_account.sip_accountable_type == 'User'
      "/tenants/#{object.sip_account.sip_accountable.current_tenant.id}/users/#{object.sip_account.sip_accountable.id}"
    else
      nil
    end
  end
end