class Monban::UseCase::Account::Change::Roles

Public Instance Methods

change(params) click to toggle source
# 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_exists?(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