feat: Add team assignment & filter APIs (#1712)

This commit is contained in:
Sojan Jose
2021-01-31 12:40:02 +05:30
committed by GitHub
parent b0563a666e
commit 0ff81e3b53
4 changed files with 70 additions and 5 deletions

View File

@@ -1,9 +1,20 @@
class Api::V1::Accounts::Conversations::AssignmentsController < Api::V1::Accounts::Conversations::BaseController
# assign agent to a conversation
# assigns agent/team to a conversation
def create
set_assignee
render json: @assignee
end
private
def set_assignee
# if params[:assignee_id] is not a valid id, it will set to nil, hence unassigning the conversation
assignee = Current.account.users.find_by(id: params[:assignee_id])
@conversation.update_assignee(assignee)
render json: assignee
if params.key?(:assignee_id)
@assignee = Current.account.users.find_by(id: params[:assignee_id])
@conversation.update_assignee(@assignee)
elsif params.key?(:team_id)
@assignee = Current.account.teams.find_by(id: params[:team_id])
@conversation.update!(team: @assignee)
end
end
end