summaryrefslogtreecommitdiff
path: root/app/serializers
diff options
context:
space:
mode:
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/phone_number_serializer.rb3
-rw-r--r--app/serializers/sip_account_serializer.rb6
-rw-r--r--app/serializers/switchboard_entry_serializer.rb13
-rw-r--r--app/serializers/switchboard_serializer.rb9
4 files changed, 25 insertions, 6 deletions
diff --git a/app/serializers/phone_number_serializer.rb b/app/serializers/phone_number_serializer.rb
new file mode 100644
index 0000000..865534b
--- /dev/null
+++ b/app/serializers/phone_number_serializer.rb
@@ -0,0 +1,3 @@
+class PhoneNumberSerializer < ActiveModel::Serializer
+ attributes :id, :name, :number
+end
diff --git a/app/serializers/sip_account_serializer.rb b/app/serializers/sip_account_serializer.rb
new file mode 100644
index 0000000..c85c8a0
--- /dev/null
+++ b/app/serializers/sip_account_serializer.rb
@@ -0,0 +1,6 @@
+class SipAccountSerializer < ActiveModel::Serializer
+ embed :ids, :include => true
+
+ attributes :id, :auth_name, :caller_name, :sip_accountable_id
+ has_many :phone_numbers
+end
diff --git a/app/serializers/switchboard_entry_serializer.rb b/app/serializers/switchboard_entry_serializer.rb
index 0b5f4c1..1b6c761 100644
--- a/app/serializers/switchboard_entry_serializer.rb
+++ b/app/serializers/switchboard_entry_serializer.rb
@@ -1,5 +1,14 @@
class SwitchboardEntrySerializer < ActiveModel::Serializer
- attributes :id, :name
+ attributes :id, :name, :path_to_user, :avatar_src, :callstate
- has_many :phone_numbers, embed: :ids
+ 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
diff --git a/app/serializers/switchboard_serializer.rb b/app/serializers/switchboard_serializer.rb
index 2912a56..600c79a 100644
--- a/app/serializers/switchboard_serializer.rb
+++ b/app/serializers/switchboard_serializer.rb
@@ -1,7 +1,8 @@
class SwitchboardSerializer < ActiveModel::Serializer
- attributes :id, :name
-
- embed :ids
+ embed :ids, :include => true
- has_many :switchboard_entries, :key => :switchboard_entrys
+ attributes :id, :name
+ has_many :switchboard_entries
+ has_many :sip_accounts, :through => :switchboard_entries
+ has_many :phone_numbers
end