Class: Accounts::CentralAgentAccountRepository

Inherits:
Object
  • Object
show all
Defined in:
app/repositories/accounts/central_agent_account_repository.rb

Class Method Summary collapse

Instance Method Summary collapse

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.(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 (user)
  return unless user
  return if user.accounts.central_agents.any?

   = ::.new(type_id: ::Dictionaries::AccountType::CENTRAL_AGENT)
  central = ::Accounts::CentralAgent.new(account: )

  .user   = user
  .name   = user.name.to_s
  .active = true
  user.is_notify = true

  ActiveRecord::Base.transaction do
    .save
    central.save
    user.save
    ::Accounts::CentralAgents::AddStatus.call .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 (user)
  return unless user
  return unless user.accounts.central_agents.any?

   = user.accounts.central_agents.first
  central = .central_agent

  ActiveRecord::Base.transaction do
    central.destroy
    .destroy
  end
end