Class: Monban::UseCase::Account::Change::Roles

Inherits:
Base
  • Object
show all
Defined in:
lib/monban/use_case/account/change/roles.rb

Instance Method Summary collapse

Instance Method Details

#change(params) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/monban/use_case/account/change/roles.rb', line 25

def change(params)
  Getto::Params.new.validate(params) do |v|
    v.hash(
      account_id: v.integer                                {|val| param_error!(account_id: val) },
      roles:      v.array_include(accept_roles.map(&:to_s)){|val| param_error!(roles: val) },
    )
  end or param_error!(params: params)

  repository.transaction do
    unless repository.(account_id: params[:account_id])
      error.not_found! "account_id: #{params[:account_id]}"
    end

    repository.update_roles(
      account_id: params[:account_id],
      roles:      params[:roles],
      now:        time.now,
    )

    repository.roles(account_id: params[:account_id])
  end
end