feat: allow querying reporting events via the API (#12832)

This commit is contained in:
Shivam Mishra
2025-11-13 12:46:55 +05:30
committed by GitHub
parent f455e7994e
commit 4f09c2203c
22 changed files with 1373 additions and 5 deletions

View File

@@ -0,0 +1,30 @@
class Api::V1::Accounts::ReportingEventsController < Api::V1::Accounts::EnterpriseAccountsController
include DateRangeHelper
RESULTS_PER_PAGE = 25
before_action :check_admin_authorization?
before_action :set_reporting_events, only: [:index]
before_action :set_current_page, only: [:index]
def index
@reporting_events = @reporting_events.page(@current_page).per(RESULTS_PER_PAGE)
@total_count = @reporting_events.total_count
end
private
def set_reporting_events
@reporting_events = Current.account.reporting_events
.includes(:conversation, :user, :inbox)
.filter_by_date_range(range)
.filter_by_inbox_id(params[:inbox_id])
.filter_by_user_id(params[:user_id])
.filter_by_name(params[:name])
.order(created_at: :desc)
end
def set_current_page
@current_page = (params[:page] || 1).to_i
end
end

View File

@@ -11,6 +11,10 @@ module Enterprise::Api::V1::Accounts::ConversationsController
end
end
def reporting_events
@reporting_events = @conversation.reporting_events.order(created_at: :asc)
end
def permitted_update_params
super.merge(params.permit(:sla_policy_id))
end

View File

@@ -0,0 +1,3 @@
json.array! @reporting_events do |reporting_event|
json.partial! 'api/v1/models/reporting_event', formats: [:json], reporting_event: reporting_event
end

View File

@@ -0,0 +1,11 @@
json.payload do
json.array! @reporting_events do |reporting_event|
json.partial! 'api/v1/models/reporting_event', formats: [:json], reporting_event: reporting_event
end
end
json.meta do
json.count @total_count
json.current_page @current_page
json.total_pages @reporting_events.total_pages
end

View File

@@ -0,0 +1,12 @@
json.id reporting_event.id
json.name reporting_event.name
json.value reporting_event.value
json.value_in_business_hours reporting_event.value_in_business_hours
json.event_start_time reporting_event.event_start_time
json.event_end_time reporting_event.event_end_time
json.account_id reporting_event.account_id
json.inbox_id reporting_event.inbox_id
json.user_id reporting_event.user_id
json.conversation_id reporting_event.conversation_id
json.created_at reporting_event.created_at
json.updated_at reporting_event.updated_at