Chatwoot/app/controllers/api/v1/accounts/conversations/assignments_controller.rb

35 lines
800 B
Ruby
Raw Normal View History

class Api::V1::Accounts::Conversations::AssignmentsController < Api::V1::Accounts::Conversations::BaseController
# assigns agent/team to a conversation
def create
if params.key?(:assignee_id)
set_agent
elsif params.key?(:team_id)
set_team
else
render json: nil
end
end
private
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 }
end
end
def set_team
@team = Current.account.teams.find_by(id: params[:team_id])
@conversation.update!(team: @team)
render json: @team
end
end