set count of the conversations and updated specs
This commit is contained in:
parent
e2cb2c34fa
commit
01f1d5216f
6 changed files with 162 additions and 110 deletions
|
@ -33,13 +33,14 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
|||
|
||||
def filter
|
||||
@conversations = ::Conversations::FilterService.new(JSON.parse(params[:body]), current_user).perform
|
||||
@conversations_count = @conversations.count
|
||||
end
|
||||
|
||||
def mute
|
||||
@conversation.mute!
|
||||
head :ok
|
||||
end
|
||||
|
||||
F
|
||||
def unmute
|
||||
@conversation.unmute!
|
||||
head :ok
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
class Conversations::FilterService < FilterService
|
||||
def perform
|
||||
conversation_query_builder
|
||||
@conversations = conversation_query_builder
|
||||
mine_count, unassigned_count, all_count, = set_count_for_all_conversations
|
||||
assigned_count = all_count - unassigned_count
|
||||
|
||||
{
|
||||
conversations: @conversations,
|
||||
count: {
|
||||
mine_count: mine_count,
|
||||
assigned_count: assigned_count,
|
||||
unassigned_count: unassigned_count,
|
||||
all_count: all_count
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def conversation_query_builder
|
||||
|
|
|
@ -33,12 +33,18 @@ class FilterService
|
|||
end
|
||||
|
||||
def filter_values(query_hash)
|
||||
values = query_hash['values'].map { |x| x['name'].downcase }
|
||||
|
||||
if query_hash['attribute_key'] == 'status'
|
||||
values.collect { |v| Conversation.statuses[v] }
|
||||
if query_hash['attribute_key'] == 'labels' || query_hash['attribute_key'] == 'browser_language'
|
||||
query_hash['values'].map { |x| x['name'] }
|
||||
else
|
||||
values
|
||||
query_hash['values'].map { |x| x['id'] }
|
||||
end
|
||||
end
|
||||
|
||||
def set_count_for_all_conversations
|
||||
[
|
||||
@conversations.assigned_to(@user).count,
|
||||
@conversations.unassigned.count,
|
||||
@conversations.count
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
json.meta do
|
||||
json.mine_count @conversations_count[:mine_count]
|
||||
json.unassigned_count @conversations_count[:unassigned_count]
|
||||
json.all_count @conversations_count[:all_count]
|
||||
end
|
||||
json.payload do
|
||||
json.array! @conversations do |conversation|
|
||||
json.partial! 'api/v1/models/conversation.json.jbuilder', conversation: conversation
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{
|
||||
"conversations":
|
||||
{
|
||||
"conversations": {
|
||||
"status": {
|
||||
"attribute_name": "Status",
|
||||
"input_type": "multi_select",
|
||||
|
@ -79,8 +78,7 @@
|
|||
"attribute_type": "additional_attributes"
|
||||
}
|
||||
},
|
||||
"contacts":
|
||||
{
|
||||
"contacts": {
|
||||
"company_name": {
|
||||
"attribute_name": "Company Name",
|
||||
"input_type": "multi_select",
|
||||
|
@ -94,6 +92,6 @@
|
|||
"data_type": "text",
|
||||
"filter_operators": [ "equal_to", "not_equal_to", "contains", "does_not_contain" ],
|
||||
"attribute_type": "additional_attributes"
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,13 +29,27 @@ describe ::Conversations::FilterService do
|
|||
{
|
||||
attribute_key: 'browser_language',
|
||||
filter_operator: 'equal_to',
|
||||
values: ['en'],
|
||||
values: [
|
||||
{
|
||||
id: 0,
|
||||
name: 'en'
|
||||
}
|
||||
],
|
||||
query_operator: 'AND'
|
||||
},
|
||||
{
|
||||
attribute_key: 'status',
|
||||
filter_operator: 'equal_to',
|
||||
values: [1, 2],
|
||||
values: [
|
||||
{
|
||||
id: 0,
|
||||
name: 'open'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'pending'
|
||||
}
|
||||
],
|
||||
query_operator: nil
|
||||
}
|
||||
]
|
||||
|
@ -48,23 +62,37 @@ describe ::Conversations::FilterService do
|
|||
end
|
||||
|
||||
it 'filter conversations by tags' do
|
||||
conversations.last.labels << 'support'
|
||||
Conversation.last.update_labels('support')
|
||||
params = [
|
||||
{
|
||||
attribute_key: 'assignee_id',
|
||||
filter_operator: 'equal_to',
|
||||
values: [user_1.id, user_2.id],
|
||||
values: [
|
||||
{
|
||||
id: user_1.id,
|
||||
name: user_1.name
|
||||
},
|
||||
{
|
||||
id: user_2.id,
|
||||
name: user_2.name
|
||||
}
|
||||
],
|
||||
query_operator: 'AND'
|
||||
},
|
||||
{
|
||||
attribute_key: 'labels',
|
||||
filter_operator: 'equal_to',
|
||||
values: ['support'],
|
||||
values: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'support'
|
||||
}
|
||||
],
|
||||
query_operator: nil
|
||||
}
|
||||
]
|
||||
result = filter_service.new(params, user_1).perform
|
||||
expect(result.length).to be 5
|
||||
expect(result.length).to be 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue