Class: Accounts::CentralAgentAccountRepository
- Inherits:
-
Object
- Object
- Accounts::CentralAgentAccountRepository
- Defined in:
- app/repositories/accounts/central_agent_account_repository.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#create_account(user) ⇒ Object
todo-my: перевести в self.
-
#destroy_account(user) ⇒ Object
todo-my: перевести в self.
Class Method Details
.fetch_or_create(user) ⇒ Object
41 42 43 44 45 |
# File 'app/repositories/accounts/central_agent_account_repository.rb', line 41 def self.fetch_or_create(user) return unless user return user.accounts.central_agents.first.central_agent if user.accounts.central_agents.any? new.create_account(user) end |
Instance Method Details
#create_account(user) ⇒ Object
todo-my: перевести в self.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/repositories/accounts/central_agent_account_repository.rb', line 5 def create_account(user) return unless user return if user.accounts.central_agents.any? account = ::Account.new(type_id: ::Dictionaries::AccountType::CENTRAL_AGENT) central = ::Accounts::CentralAgent.new(account: account) account.user = user account.name = user.name.to_s account.active = true user.is_notify = true ActiveRecord::Base.transaction do account.save central.save user.save ::Accounts::CentralAgents::AddStatus.call account.id end central end |
#destroy_account(user) ⇒ Object
todo-my: перевести в self.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/repositories/accounts/central_agent_account_repository.rb', line 28 def destroy_account(user) return unless user return unless user.accounts.central_agents.any? account = user.accounts.central_agents.first central = account.central_agent ActiveRecord::Base.transaction do central.destroy account.destroy end end |