Class: CommandTower::Workflows::Me::UpdatePhoneWorkflow

Inherits:
ApplicationWorkflow show all
Defined in:
app/workflows/command_tower/workflows/me/update_phone_workflow.rb

Constant Summary

Constants inherited from ApplicationWorkflow

ApplicationWorkflow::ALLOWED_RETRY_STRATEGIES, ApplicationWorkflow::InvalidTransactionResult, ApplicationWorkflow::TransactionFailure

Instance Method Summary collapse

Methods inherited from ApplicationWorkflow

call, call_from_job, continuation_max_attempts, declared_retry_strategy, mark_impersonation_activity!, retry_strategy, validate_retry_strategy!

Methods included from Impersonation::ActivityDeclaration

included

Methods included from Logging::LifecycleDeclaration

included

Methods included from Execution::ContextAccess

#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event

Methods included from Transactional

#fail_transaction!, #transaction

Instance Method Details

#call(current_user:, phone_number:, auth_context: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/workflows/command_tower/workflows/me/update_phone_workflow.rb', line 9

def call(current_user:, phone_number:, auth_context: nil)
  unless CommandTower::Services::Me::SmsProductGate.enabled?
    error = CommandTower::Errors::Account::SmsCapabilityUnavailableError.new
    return failure(
      errors: [error],
      http_status: CommandTower::Workflows::Me::ErrorMapping.http_status_for(error)
    )
  end

  update_result = CommandTower::Services::Account::UpdatePhone.call(
    user: current_user,
    phone_number:
  )

  unless update_result.success?
    error = update_result.errors.first
    return failure(
      errors: update_result.errors,
      http_status: CommandTower::Workflows::Me::ErrorMapping.http_status_for(error)
    )
  end

  user = update_result.data[:user].reload
  capabilities = CommandTower::Services::Me::Capabilities.project(user)
  payload = CommandTower::Serializers::Me::AccountSerializer.serialize(
    user,
    capabilities: capabilities
  )

  success(
    payload: payload,
    http_status: :ok,
    response_effects: expire_header_effects(auth_context)
  )
end