Sha256: 659ae3e9b85325a2a3f12156db27a727dd91a1e204bfe7dad6405c57d06ff87a

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

require "monban/core"
require "monban/use_case/base"

require "getto/params"

module Monban
  module UseCase
    module Account
      module Change
        class Roles < Base

          initialize_with(
            error: Monban::Core::ERRORS,
            time:  [:now],
            repository: [
              :transaction,
              :account_exists?,
              :update_roles,
              :roles,
            ],

            accept_roles: Array,
          )

          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

        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
monban-core-1.2.4 lib/monban/use_case/account/change/roles.rb
monban-core-1.2.3 lib/monban/use_case/account/change/roles.rb
monban-core-1.2.2 lib/monban/use_case/account/change/roles.rb
monban-core-1.1.0 lib/monban/use_case/account/change/roles.rb
monban-core-1.0.3 lib/monban/use_case/account/change/roles.rb
monban-core-1.0.2 lib/monban/use_case/account/change/roles.rb
monban-core-1.0.0 lib/monban/use_case/account/change/roles.rb