mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
44 lines
1.0 KiB
Ruby
44 lines
1.0 KiB
Ruby
class Api::V2::Accounts::SummaryReportsController < Api::V1::Accounts::BaseController
|
|
before_action :check_authorization
|
|
before_action :prepare_builder_params, only: [:agent, :team, :inbox, :label]
|
|
|
|
def agent
|
|
render_report_with(V2::Reports::AgentSummaryBuilder)
|
|
end
|
|
|
|
def team
|
|
render_report_with(V2::Reports::TeamSummaryBuilder)
|
|
end
|
|
|
|
def inbox
|
|
render_report_with(V2::Reports::InboxSummaryBuilder)
|
|
end
|
|
|
|
def label
|
|
render_report_with(V2::Reports::LabelSummaryBuilder)
|
|
end
|
|
|
|
private
|
|
|
|
def check_authorization
|
|
authorize :report, :view?
|
|
end
|
|
|
|
def prepare_builder_params
|
|
@builder_params = {
|
|
since: permitted_params[:since],
|
|
until: permitted_params[:until],
|
|
business_hours: ActiveModel::Type::Boolean.new.cast(permitted_params[:business_hours])
|
|
}
|
|
end
|
|
|
|
def render_report_with(builder_class)
|
|
builder = builder_class.new(account: Current.account, params: @builder_params)
|
|
render json: builder.build
|
|
end
|
|
|
|
def permitted_params
|
|
params.permit(:since, :until, :business_hours)
|
|
end
|
|
end
|