chore: Add assigned_count to conversation APIs (#2665)

This commit is contained in:
Sojan Jose
2021-07-19 19:10:58 +05:30
committed by GitHub
parent a235e82a02
commit 217dd8a6f0
7 changed files with 40 additions and 18 deletions

View File

@@ -21,6 +21,27 @@ class ConversationFinder
end
def perform
set_up
mine_count, unassigned_count, all_count, = set_count_for_all_conversations
assigned_count = all_count - unassigned_count
filter_by_assignee_type
{
conversations: conversations,
count: {
mine_count: mine_count,
assigned_count: assigned_count,
unassigned_count: unassigned_count,
all_count: all_count
}
}
end
private
def set_up
set_inboxes
set_team
set_assignee_type
@@ -30,23 +51,8 @@ class ConversationFinder
filter_by_team if @team
filter_by_labels if params[:labels]
filter_by_query if params[:q]
mine_count, unassigned_count, all_count = set_count_for_all_conversations
filter_by_assignee_type
{
conversations: conversations,
count: {
mine_count: mine_count,
unassigned_count: unassigned_count,
all_count: all_count
}
}
end
private
def set_inboxes
@inbox_ids = if params[:inbox_id]
current_account.inboxes.where(id: params[:inbox_id])
@@ -74,7 +80,7 @@ class ConversationFinder
when 'unassigned'
@conversations = @conversations.unassigned
when 'assigned'
@conversations = @conversations.where.not(assignee_id: nil)
@conversations = @conversations.assigned
end
@conversations
end

View File

@@ -49,6 +49,7 @@ class Conversation < ApplicationRecord
scope :latest, -> { order(last_activity_at: :desc) }
scope :unassigned, -> { where(assignee_id: nil) }
scope :assigned, -> { where.not(assignee_id: nil) }
scope :assigned_to, ->(agent) { where(assignee_id: agent.id) }
belongs_to :account

View File

@@ -1,6 +1,7 @@
json.data do
json.meta do
json.mine_count @conversations_count[:mine_count]
json.assigned_count @conversations_count[:assigned_count]
json.unassigned_count @conversations_count[:unassigned_count]
json.all_count @conversations_count[:all_count]
end

View File

@@ -1,5 +1,6 @@
json.meta do
json.mine_count @conversations_count[:mine_count]
json.assigned_count @conversations_count[:assigned_count]
json.unassigned_count @conversations_count[:unassigned_count]
json.all_count @conversations_count[:all_count]
end