2020-06-07 08:28:05 +00:00
|
|
|
class Api::V1::Accounts::Conversations::AssignmentsController < Api::V1::Accounts::Conversations::BaseController
|
2021-01-31 07:10:02 +00:00
|
|
|
# assigns agent/team to a conversation
|
2020-03-09 17:57:10 +00:00
|
|
|
def create
|
2021-09-13 08:13:19 +00:00
|
|
|
if params.key?(:assignee_id)
|
|
|
|
set_agent
|
|
|
|
elsif params.key?(:team_id)
|
|
|
|
set_team
|
|
|
|
else
|
|
|
|
render json: nil
|
|
|
|
end
|
2021-01-31 07:10:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-09-13 08:13:19 +00:00
|
|
|
def set_agent
|
|
|
|
@agent = Current.account.users.find_by(id: params[:assignee_id])
|
|
|
|
@conversation.update_assignee(@agent)
|
|
|
|
render_agent
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_agent
|
|
|
|
if @agent.nil?
|
|
|
|
render json: nil
|
|
|
|
else
|
|
|
|
render partial: 'api/v1/models/agent', formats: [:json], locals: { resource: @agent }
|
2021-01-31 07:10:02 +00:00
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
2021-09-13 08:13:19 +00:00
|
|
|
|
|
|
|
def set_team
|
|
|
|
@team = Current.account.teams.find_by(id: params[:team_id])
|
|
|
|
@conversation.update!(team: @team)
|
|
|
|
render json: @team
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|