Class: Jumbotron::Services::Canonical::UpsertTeam

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

Instance Method Summary collapse

Instance Method Details

#callObject



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
# File 'app/services/jumbotron/services/canonical/upsert_team.rb', line 11

def call
  ref = team_input.provider_identities.first
  identity = ProviderIdentity.find_by(
    provider: ref.provider,
    object_namespace: ref.namespace,
    provider_id: ref.id
  )

  team = resolve_team(identity)

  attach = AttachProviderIdentities.call(target: team, refs: team_input.provider_identities)
  unless attach.success?
    context.fail!(application_error: attach.errors.first)
    return
  end

  context.team = team
rescue ActiveRecord::RecordNotUnique
  context.team = recover_after_race!
rescue ActiveRecord::RecordInvalid => e
  context.fail!(
    application_error: Jumbotron::Errors::Canonical::MutationFailedError.new(
      details: { message: e.message }
    )
  )
end