feat: API to Filter reports by teams (#3066)
Add API to Filter reports by teams Fixes: #2916
This commit is contained in:
@@ -41,19 +41,25 @@ class V2::ReportBuilder
|
||||
user
|
||||
when :label
|
||||
label
|
||||
when :team
|
||||
team
|
||||
end
|
||||
end
|
||||
|
||||
def inbox
|
||||
@inbox ||= account.inboxes.where(id: params[:id]).first
|
||||
@inbox ||= account.inboxes.find(params[:id])
|
||||
end
|
||||
|
||||
def user
|
||||
@user ||= account.users.where(id: params[:id]).first
|
||||
@user ||= account.users.find(params[:id])
|
||||
end
|
||||
|
||||
def label
|
||||
@label ||= account.labels.where(id: params[:id]).first
|
||||
@label ||= account.labels.find(params[:id])
|
||||
end
|
||||
|
||||
def team
|
||||
@team ||= account.teams.find(params[:id])
|
||||
end
|
||||
|
||||
def conversations_count
|
||||
|
||||
@@ -29,6 +29,12 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
render layout: false, template: 'api/v2/accounts/reports/labels.csv.erb', format: 'csv'
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def check_authorization
|
||||
|
||||
@@ -40,4 +40,12 @@ class Team < ApplicationRecord
|
||||
def remove_member(user_id)
|
||||
team_members.find_by(user_id: user_id)&.destroy
|
||||
end
|
||||
|
||||
def messages
|
||||
account.messages.where(conversation_id: conversations.pluck(:id))
|
||||
end
|
||||
|
||||
def events
|
||||
account.events.where(conversation_id: conversations.pluck(:id))
|
||||
end
|
||||
end
|
||||
|
||||
19
app/views/api/v2/accounts/reports/teams.csv.erb
Normal file
19
app/views/api/v2/accounts/reports/teams.csv.erb
Normal file
@@ -0,0 +1,19 @@
|
||||
<% headers = [
|
||||
I18n.t('reports.team_csv.team_name'),
|
||||
I18n.t('reports.team_csv.conversations_count'),
|
||||
I18n.t('reports.team_csv.avg_first_response_time'),
|
||||
I18n.t('reports.team_csv.avg_resolution_time')
|
||||
]
|
||||
%>
|
||||
<%= CSV.generate_line headers %>
|
||||
<% Current.account.teams.each do |team| %>
|
||||
<% team_report = V2::ReportBuilder.new(Current.account, {
|
||||
type: :team,
|
||||
id: team.id,
|
||||
since: params[:since],
|
||||
until: params[:until]
|
||||
}).summary %>
|
||||
<% row = [ team.name, team_report[:conversations_count], (team_report[:avg_first_response_time]/60).to_i, (team_report[:avg_resolution_time]/60).to_i ] %>
|
||||
<%= CSV.generate_line row %>
|
||||
<% end %>
|
||||
<%= CSV.generate_line [I18n.t('reports.period', since: Date.strptime(params[:since], '%s'), until: Date.strptime(params[:until], '%s'))] %>
|
||||
Reference in New Issue
Block a user