Class: CommandTower::Workflows::Messaging::Preferences::UpdateWorkflow

Inherits:
ApplicationWorkflow show all
Defined in:
app/workflows/command_tower/workflows/messaging/preferences/update_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(user:, notification_type_key:, preference_state:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/workflows/command_tower/workflows/messaging/preferences/update_workflow.rb', line 10

def call(user:, notification_type_key:, preference_state:)
  result = CommandTower::Services::Messaging::Preferences::Update.call(
    user:,
    notification_type_key:,
    preference_state:,
  )

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

  payload = {
    notification: CommandTower::Serializers::Messaging::Preferences::NotificationSerializer.serialize(
      result.data[:notification],
    ),
  }

  success(payload:, http_status: :ok)
end