feat: Agent & Inbox Report APIs (#1391)
This commit is contained in:
@@ -9,6 +9,18 @@ class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
|
||||
render json: account_summary_metrics
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def account_summary_params
|
||||
|
||||
@@ -12,8 +12,8 @@ class ReportsAPI extends ApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
getAccountSummary(accountId, since, until) {
|
||||
return axios.get(`${this.url}/${accountId}/account_summary`, {
|
||||
getAccountSummary(since, until) {
|
||||
return axios.get(`${this.url}/account_summary`, {
|
||||
params: { since, until },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ const actions = {
|
||||
});
|
||||
},
|
||||
fetchAccountSummary({ commit }, reportObj) {
|
||||
Report.getAccountSummary(1, reportObj.from, reportObj.to)
|
||||
Report.getAccountSummary(reportObj.from, reportObj.to)
|
||||
.then(accountSummary => {
|
||||
commit(types.default.SET_ACCOUNT_SUMMARY, accountSummary.data);
|
||||
})
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# name :string not null
|
||||
# settings_flags :integer default(0), not null
|
||||
# support_email :string(100)
|
||||
# timezone :string default("UTC")
|
||||
# timezone :string default("UTC")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
@@ -66,6 +66,8 @@ class User < ApplicationRecord
|
||||
accepts_nested_attributes_for :account_users
|
||||
|
||||
has_many :assigned_conversations, foreign_key: 'assignee_id', class_name: 'Conversation', dependent: :nullify
|
||||
alias_attribute :conversations, :assigned_conversations
|
||||
|
||||
has_many :inbox_members, dependent: :destroy
|
||||
has_many :inboxes, through: :inbox_members, source: :inbox
|
||||
has_many :messages, as: :sender
|
||||
|
||||
12
app/views/api/v2/accounts/reports/agents.csv.erb
Normal file
12
app/views/api/v2/accounts/reports/agents.csv.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<% headers = ['Agent name', 'Conversations count', 'Avg first response time (Minutes)', 'Avg resolution time (Minutes)'] %>
|
||||
<%= CSV.generate_line headers %>
|
||||
<% Current.account.users.each do |agent| %>
|
||||
<% agent_report = V2::ReportBuilder.new(Current.account, {
|
||||
type: :agent,
|
||||
id: agent.id,
|
||||
since: params[:since],
|
||||
until: params[:until]
|
||||
}).summary %>
|
||||
<% row = [ agent.name, agent_report[:conversations_count], (agent_report[:avg_first_response_time]/60).to_i, (agent_report[:avg_resolution_time]/60).to_i ] %>
|
||||
<%= CSV.generate_line row %>
|
||||
<% end %>
|
||||
12
app/views/api/v2/accounts/reports/inboxes.csv.erb
Normal file
12
app/views/api/v2/accounts/reports/inboxes.csv.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<% headers = ['Inbox name', 'Conversations count', 'Avg first response time (Minutes)', 'Avg resolution time (Minutes)'] %>
|
||||
<%= CSV.generate_line headers %>
|
||||
<% Current.account.inboxes.each do |inbox| %>
|
||||
<% inbox_report = V2::ReportBuilder.new(Current.account, {
|
||||
type: :inbox,
|
||||
id: inbox.id,
|
||||
since: params[:since],
|
||||
until: params[:until]
|
||||
}).summary %>
|
||||
<% row = [ inbox.name, inbox_report[:conversations_count], (inbox_report[:avg_first_response_time]/60).to_i, (inbox_report[:avg_resolution_time]/60).to_i ] %>
|
||||
<%= CSV.generate_line row %>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user