mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-08 06:53:26 +00:00
36 lines
818 B
Ruby
36 lines
818 B
Ruby
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.assignee = @agent
|
|
@conversation.save!
|
|
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
|