feat: Team APIs (#1654)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
24
app/controllers/api/v1/accounts/team_members_controller.rb
Normal file
24
app/controllers/api/v1/accounts/team_members_controller.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class Api::V1::Accounts::TeamMembersController < Api::V1::Accounts::BaseController
|
||||
before_action :fetch_team
|
||||
before_action :check_authorization
|
||||
|
||||
def index
|
||||
@team_members = @team.team_members.map(&:user)
|
||||
end
|
||||
|
||||
def create
|
||||
record = @team.team_members.find_or_create_by(user_id: params[:user_id])
|
||||
@team_member = record.user
|
||||
end
|
||||
|
||||
def destroy
|
||||
@team.team_members.find_by(user_id: params[:user_id])&.destroy
|
||||
head :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_team
|
||||
@team = Current.account.teams.find(params[:team_id])
|
||||
end
|
||||
end
|
||||
34
app/controllers/api/v1/accounts/teams_controller.rb
Normal file
34
app/controllers/api/v1/accounts/teams_controller.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
class Api::V1::Accounts::TeamsController < Api::V1::Accounts::BaseController
|
||||
before_action :fetch_team, only: [:show, :update, :destroy]
|
||||
before_action :check_authorization
|
||||
|
||||
def index
|
||||
@teams = Current.account.teams
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@team = Current.account.teams.new(team_params)
|
||||
@team.save!
|
||||
end
|
||||
|
||||
def update
|
||||
@team.update!(team_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@team.destroy
|
||||
head :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_team
|
||||
@team = Current.account.teams.find(params[:id])
|
||||
end
|
||||
|
||||
def team_params
|
||||
params.require(:team).permit(:name, :description, :allow_auto_assign)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user