feat: Add SLA metrics API (#9132)

This commit is contained in:
Muhsin Keloth
2024-03-25 12:24:43 +05:30
committed by GitHub
parent 6d4551bca2
commit 48452a42f4
7 changed files with 284 additions and 0 deletions

View File

@@ -29,6 +29,17 @@ class AppliedSla < ApplicationRecord
enum sla_status: { active: 0, hit: 1, missed: 2 }
scope :filter_by_date_range, ->(range) { where(created_at: range) if range.present? }
scope :filter_by_inbox_id, ->(inbox_id) { where(inbox_id: inbox_id) if inbox_id.present? }
scope :filter_by_team_id, ->(team_id) { where(team_id: team_id) if team_id.present? }
scope :filter_by_sla_policy_id, ->(sla_policy_id) { where(sla_policy_id: sla_policy_id) if sla_policy_id.present? }
scope :filter_by_label_list, ->(label_list) { joins(:conversation).where(conversations: { cached_label_list: label_list }) if label_list.present? }
scope :filter_by_assigned_agent_id, lambda { |assigned_agent_id|
if assigned_agent_id.present?
joins(:conversation).where(conversations: { assigned_agent_id: assigned_agent_id })
end
}
scope :missed, -> { where(sla_status: :missed) }
private
def ensure_account_id