feat: Conversation API to return applied_sla and sla_events (#9174)
* chore: Add sla_events to push_event_data * chore: Return SLA details in the API * chore: feature lock sla push event data * Update _conversation.json.jbuilder * chore: rubocop fixes
This commit is contained in:
@@ -1,8 +1,2 @@
|
||||
class Api::V1::Accounts::EnterpriseAccountsController < Api::V1::Accounts::BaseController
|
||||
before_action :prepend_view_paths
|
||||
|
||||
# Prepend the view path to the enterprise/app/views won't be available by default
|
||||
def prepend_view_paths
|
||||
prepend_view_path 'enterprise/app/views/'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
module Enterprise::Concerns::ApplicationControllerConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :prepend_view_paths
|
||||
end
|
||||
|
||||
# Prepend the view path to the enterprise/app/views won't be available by default
|
||||
def prepend_view_paths
|
||||
prepend_view_path 'enterprise/app/views/'
|
||||
end
|
||||
end
|
||||
5
enterprise/app/finders/enterprise/conversation_finder.rb
Normal file
5
enterprise/app/finders/enterprise/conversation_finder.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module Enterprise::ConversationFinder
|
||||
def conversations_base_query
|
||||
current_account.feature_enabled?('sla') ? super.includes(:applied_sla, :sla_events) : super
|
||||
end
|
||||
end
|
||||
@@ -40,6 +40,23 @@ class AppliedSla < ApplicationRecord
|
||||
end
|
||||
}
|
||||
scope :missed, -> { where(sla_status: :missed) }
|
||||
|
||||
def push_event_data
|
||||
{
|
||||
id: id,
|
||||
sla_id: sla_policy_id,
|
||||
sla_status: sla_status,
|
||||
created_at: created_at.to_i,
|
||||
updated_at: updated_at.to_i,
|
||||
sla_description: sla_policy.description,
|
||||
sla_name: sla_policy.name,
|
||||
sla_first_response_time_threshold: sla_policy.first_response_time_threshold,
|
||||
sla_next_response_time_threshold: sla_policy.next_response_time_threshold,
|
||||
sla_only_during_business_hours: sla_policy.only_during_business_hours,
|
||||
sla_resolution_time_threshold: sla_policy.resolution_time_threshold
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure_account_id
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
module Enterprise::EnterpriseConversationConcern
|
||||
module Enterprise::Concerns::Conversation
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
belongs_to :sla_policy, optional: true
|
||||
has_one :applied_sla, dependent: :destroy
|
||||
has_one :applied_sla, dependent: :destroy_async
|
||||
has_many :sla_events, dependent: :destroy_async
|
||||
before_validation :validate_sla_policy, if: -> { sla_policy_id_changed? }
|
||||
around_save :ensure_applied_sla_is_created, if: -> { sla_policy_id_changed? }
|
||||
end
|
||||
@@ -31,9 +31,18 @@ class SlaEvent < ApplicationRecord
|
||||
enum event_type: { frt: 0, nrt: 1, rt: 2 }
|
||||
|
||||
before_validation :ensure_applied_sla_id, :ensure_account_id, :ensure_inbox_id, :ensure_sla_policy_id
|
||||
|
||||
after_create_commit :create_notifications
|
||||
|
||||
def push_event_data
|
||||
{
|
||||
id: id,
|
||||
event_type: event_type,
|
||||
meta: meta,
|
||||
created_at: created_at.to_i,
|
||||
updated_at: updated_at.to_i
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure_applied_sla_id
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
module Enterprise::Conversations::EventDataPresenter
|
||||
def push_data
|
||||
if account.feature_enabled?('sla')
|
||||
super.merge(
|
||||
applied_sla: applied_sla&.push_event_data,
|
||||
sla_events: sla_events.map(&:push_event_data)
|
||||
)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
json.id resource.id
|
||||
json.sla_id resource.sla_policy_id
|
||||
json.sla_status resource.sla_status
|
||||
json.created_at resource.created_at.to_i
|
||||
json.updated_at resource.updated_at.to_i
|
||||
json.sla_description resource.sla_policy.description
|
||||
json.sla_name resource.sla_policy.name
|
||||
json.sla_first_response_time_threshold resource.sla_policy.first_response_time_threshold
|
||||
json.sla_next_response_time_threshold resource.sla_policy.next_response_time_threshold
|
||||
json.sla_only_during_business_hours resource.sla_policy.only_during_business_hours
|
||||
json.sla_resolution_time_threshold resource.sla_policy.resolution_time_threshold
|
||||
@@ -0,0 +1,10 @@
|
||||
if conversation.account.feature_enabled?('sla')
|
||||
json.applied_sla do
|
||||
json.partial! 'api/v1/models/applied_sla', formats: [:json], resource: conversation.applied_sla if conversation.applied_sla.present?
|
||||
end
|
||||
json.sla_events do
|
||||
json.array! conversation.sla_events do |sla_event|
|
||||
json.partial! 'api/v1/models/sla_event', formats: [:json], sla_event: sla_event
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user