Class: Jumbotron::Services::Canonical::UpsertGameParticipant

Inherits:
CommandTower::Services::ApplicationService
  • Object
show all
Defined in:
app/services/jumbotron/services/canonical/upsert_game_participant.rb

Instance Method Summary collapse

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/jumbotron/services/canonical/upsert_game_participant.rb', line 12

def call
  team_result = UpsertTeam.call(
    team_input: Jumbotron::Canonical::TeamInput.new(
      provider_identities: participant_input.provider_identities,
      name: participant_input.team_name
    ),
    observed_at: observed_at,
    change_set: change_set
  )
  unless team_result.success?
    context.fail!(application_error: team_result.errors.first)
    return
  end

  team = team_result.data[:team]
  participant = game.game_participants.lock.find_by(team_id: team.id)
  context.game_participant = resolve_participant(participant, team)
rescue ActiveRecord::RecordInvalid => e
  context.fail!(
    application_error: Jumbotron::Errors::Canonical::MutationFailedError.new(
      details: { message: e.message }
    )
  )
end