Sha256: 9dd26b46766e2e990bd281a049d15c9330d8ad303f43ff5c0bb1948850814964
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true class Account class OwnerCreation < ::BCDD::Process include BCDD::Result::RollbackOnFailure input do attribute :uuid, contract: :is_uuid, normalize: -> { _1.strip.downcase }, default: -> { ::SecureRandom.uuid } attribute :owner, type: ::Hash, contract: :is_present end output do Failure( invalid_owner: ::Hash, invalid_account: :errors_by_attribute ) Success account_owner_created: { user: contract[::User] & :is_persisted, account: contract[::Account] & :is_persisted } end def call(**input) rollback_on_failure { Given(input) .and_then(:create_owner) .and_then(:create_account) .and_then(:link_owner_to_account) }.and_expose(:account_owner_created, %i[account user]) end private def create_owner(owner:, **) ::User::Creation.call(**owner).handle do |on| on.success { |output| Continue(user: output[:user]) } on.failure { |output| Failure(:invalid_owner, **output) } end end def create_account(uuid:, **) ::RuntimeBreaker.try_to_interrupt(env: 'BREAK_ACCOUNT_CREATION') account = ::Account.create(uuid:) account.persisted? ? Continue(account:) : Failure(:invalid_account, **account.errors.messages) end def link_owner_to_account(account:, user:, **) Member.create!(account:, user:, role: :owner) Continue() end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bcdd-process-0.3.1 | examples/business_processes/app/models/account/owner_creation.rb |
bcdd-process-0.3.0 | examples/business_processes/app/models/account/owner_creation.rb |