2020-06-07 08:28:05 +00:00
|
|
|
class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
2021-06-11 06:14:31 +00:00
|
|
|
before_action :check_authorization
|
|
|
|
|
2021-08-27 17:16:32 +00:00
|
|
|
def index
|
|
|
|
builder = V2::ReportBuilder.new(Current.account, report_params)
|
2020-03-18 11:23:35 +00:00
|
|
|
data = builder.build
|
|
|
|
render json: data
|
|
|
|
end
|
|
|
|
|
2021-08-27 17:16:32 +00:00
|
|
|
def summary
|
|
|
|
render json: summary_metrics
|
2020-03-18 11:23:35 +00:00
|
|
|
end
|
|
|
|
|
2020-11-16 14:11:52 +00:00
|
|
|
def agents
|
|
|
|
response.headers['Content-Type'] = 'text/csv'
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename=agents_report.csv'
|
|
|
|
render layout: false, template: 'api/v2/accounts/reports/agents.csv.erb', format: 'csv'
|
|
|
|
end
|
|
|
|
|
|
|
|
def inboxes
|
|
|
|
response.headers['Content-Type'] = 'text/csv'
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename=inboxes_report.csv'
|
|
|
|
render layout: false, template: 'api/v2/accounts/reports/inboxes.csv.erb', format: 'csv'
|
|
|
|
end
|
|
|
|
|
2021-08-27 17:16:32 +00:00
|
|
|
def labels
|
|
|
|
response.headers['Content-Type'] = 'text/csv'
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename=labels_report.csv'
|
|
|
|
render layout: false, template: 'api/v2/accounts/reports/labels.csv.erb', format: 'csv'
|
|
|
|
end
|
|
|
|
|
2021-09-27 15:42:08 +00:00
|
|
|
def teams
|
|
|
|
response.headers['Content-Type'] = 'text/csv'
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename=teams_report.csv'
|
|
|
|
render layout: false, template: 'api/v2/accounts/reports/teams.csv.erb', format: 'csv'
|
|
|
|
end
|
|
|
|
|
2020-03-18 11:23:35 +00:00
|
|
|
private
|
|
|
|
|
2021-06-11 06:14:31 +00:00
|
|
|
def check_authorization
|
|
|
|
raise Pundit::NotAuthorizedError unless Current.account_user.administrator?
|
|
|
|
end
|
|
|
|
|
2021-08-27 17:16:32 +00:00
|
|
|
def summary_params
|
2020-03-18 11:23:35 +00:00
|
|
|
{
|
2021-08-27 17:16:32 +00:00
|
|
|
type: params[:type].to_sym,
|
2020-03-18 11:23:35 +00:00
|
|
|
since: params[:since],
|
2021-08-27 17:16:32 +00:00
|
|
|
until: params[:until],
|
2022-02-15 11:40:49 +00:00
|
|
|
id: params[:id],
|
|
|
|
group_by: params[:group_by]
|
2020-03-18 11:23:35 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-08-27 17:16:32 +00:00
|
|
|
def report_params
|
2020-03-18 11:23:35 +00:00
|
|
|
{
|
|
|
|
metric: params[:metric],
|
2021-08-27 17:16:32 +00:00
|
|
|
type: params[:type].to_sym,
|
2020-03-18 11:23:35 +00:00
|
|
|
since: params[:since],
|
2021-08-27 17:16:32 +00:00
|
|
|
until: params[:until],
|
2022-02-15 11:40:49 +00:00
|
|
|
id: params[:id],
|
|
|
|
group_by: params[:group_by]
|
2020-03-18 11:23:35 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-08-27 17:16:32 +00:00
|
|
|
def summary_metrics
|
|
|
|
builder = V2::ReportBuilder.new(Current.account, summary_params)
|
2020-03-18 11:23:35 +00:00
|
|
|
builder.summary
|
|
|
|
end
|
|
|
|
end
|