chore: Update method for team members (#1734)

Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Nithin David Thomas
2021-02-09 19:21:31 +05:30
committed by GitHub
parent bf2b56a988
commit 1484849cc7
6 changed files with 76 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ class Team < ApplicationRecord
belongs_to :account
has_many :team_members, dependent: :destroy
has_many :members, through: :team_members, source: :user
has_many :conversations, dependent: :nullify
validates :name,
@@ -34,4 +35,12 @@ class Team < ApplicationRecord
before_validation do
self.name = name.downcase if attribute_present?('name')
end
def add_member(user_id)
team_members.find_or_create_by(user_id: user_id)&.user
end
def remove_member(user_id)
team_members.find_by(user_id: user_id)&.destroy
end
end