diff --git a/app/builders/v2/reports/agent_summary_builder.rb b/app/builders/v2/reports/agent_summary_builder.rb index 382c67bf5..49bd706cb 100644 --- a/app/builders/v2/reports/agent_summary_builder.rb +++ b/app/builders/v2/reports/agent_summary_builder.rb @@ -3,6 +3,7 @@ class V2::Reports::AgentSummaryBuilder < V2::Reports::BaseSummaryBuilder def build set_grouped_conversations_count + set_grouped_resolved_conversations_count set_grouped_avg_reply_time set_grouped_avg_first_response_time set_grouped_avg_resolution_time @@ -27,6 +28,10 @@ class V2::Reports::AgentSummaryBuilder < V2::Reports::BaseSummaryBuilder @grouped_avg_reply_time = get_grouped_average(reporting_events.where(name: 'reply_time')) end + def set_grouped_resolved_conversations_count + @grouped_resolved_conversations_count = reporting_events.where(name: 'conversation_resolved').group(group_by_key).count + end + def group_by_key :user_id end @@ -37,12 +42,14 @@ class V2::Reports::AgentSummaryBuilder < V2::Reports::BaseSummaryBuilder def prepare_report account.account_users.each_with_object([]) do |account_user, arr| + user_id = account_user.user_id arr << { - id: account_user.user_id, - conversations_count: @grouped_conversations_count[account_user.user_id], - avg_resolution_time: @grouped_avg_resolution_time[account_user.user_id], - avg_first_response_time: @grouped_avg_first_response_time[account_user.user_id], - avg_reply_time: @grouped_avg_reply_time[account_user.user_id] + id: user_id, + conversations_count: @grouped_conversations_count[user_id], + resolved_conversations_count: @grouped_resolved_conversations_count[user_id], + avg_resolution_time: @grouped_avg_resolution_time[user_id], + avg_first_response_time: @grouped_avg_first_response_time[user_id], + avg_reply_time: @grouped_avg_reply_time[user_id] } end end diff --git a/app/builders/v2/reports/team_summary_builder.rb b/app/builders/v2/reports/team_summary_builder.rb index 3d7e765b3..00afb7132 100644 --- a/app/builders/v2/reports/team_summary_builder.rb +++ b/app/builders/v2/reports/team_summary_builder.rb @@ -3,6 +3,7 @@ class V2::Reports::TeamSummaryBuilder < V2::Reports::BaseSummaryBuilder def build set_grouped_conversations_count + set_grouped_resolved_conversations_count set_grouped_avg_reply_time set_grouped_avg_first_response_time set_grouped_avg_resolution_time @@ -27,6 +28,10 @@ class V2::Reports::TeamSummaryBuilder < V2::Reports::BaseSummaryBuilder @grouped_avg_reply_time = get_grouped_average(reporting_events.where(name: 'reply_time')) end + def set_grouped_resolved_conversations_count + @grouped_resolved_conversations_count = reporting_events.where(name: 'conversation_resolved').group(group_by_key).count + end + def reporting_events @reporting_events ||= Current.account.reporting_events.where(created_at: range).joins(:conversation) end @@ -40,6 +45,7 @@ class V2::Reports::TeamSummaryBuilder < V2::Reports::BaseSummaryBuilder arr << { id: team.id, conversations_count: @grouped_conversations_count[team.id], + resolved_conversations_count: @grouped_resolved_conversations_count[team.id], avg_resolution_time: @grouped_avg_resolution_time[team.id], avg_first_response_time: @grouped_avg_first_response_time[team.id], avg_reply_time: @grouped_avg_reply_time[team.id] diff --git a/app/controllers/api/v2/accounts/live_reports_controller.rb b/app/controllers/api/v2/accounts/live_reports_controller.rb index 59804c988..27a06a66d 100644 --- a/app/controllers/api/v2/accounts/live_reports_controller.rb +++ b/app/controllers/api/v2/accounts/live_reports_controller.rb @@ -42,7 +42,7 @@ class Api::V2::Accounts::LiveReportsController < Api::V1::Accounts::BaseControll def team return unless permitted_params[:team_id] - @team ||= Current.account.teams.find_by(permitted_params[:team_id]) + @team ||= Current.account.teams.find(permitted_params[:team_id]) end def load_conversations diff --git a/app/javascript/dashboard/api/liveReports.js b/app/javascript/dashboard/api/liveReports.js index 759ebc2a9..1435da258 100644 --- a/app/javascript/dashboard/api/liveReports.js +++ b/app/javascript/dashboard/api/liveReports.js @@ -6,8 +6,8 @@ class LiveReportsAPI extends ApiClient { super('live_reports', { accountScoped: true, apiVersion: 'v2' }); } - getConversationMetric() { - return axios.get(`${this.url}/conversation_metrics`); + getConversationMetric(params = {}) { + return axios.get(`${this.url}/conversation_metrics`, { params }); } getGroupedConversations({ groupBy } = { groupBy: 'assignee_id' }) { diff --git a/app/javascript/dashboard/api/summaryReports.js b/app/javascript/dashboard/api/summaryReports.js new file mode 100644 index 000000000..f978ec107 --- /dev/null +++ b/app/javascript/dashboard/api/summaryReports.js @@ -0,0 +1,30 @@ +/* global axios */ +import ApiClient from './ApiClient'; + +class SummaryReportsAPI extends ApiClient { + constructor() { + super('summary_reports', { accountScoped: true, apiVersion: 'v2' }); + } + + getTeamReports({ since, until, businessHours }) { + return axios.get(`${this.url}/team`, { + params: { + since, + until, + business_hours: businessHours, + }, + }); + } + + getAgentReports({ since, until, businessHours }) { + return axios.get(`${this.url}/agents`, { + params: { + since, + until, + business_hours: businessHours, + }, + }); + } +} + +export default new SummaryReportsAPI(); diff --git a/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue b/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue index 2cf0668ba..9c8d44dc4 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/reports/LiveReports.vue @@ -1,28 +1,13 @@