Class: Jumbotron::Services::Canonical::UpsertVenue

Inherits:
CommandTower::Services::ApplicationService
  • Object
show all
Defined in:
app/services/jumbotron/services/canonical/upsert_venue.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
37
38
39
40
41
# File 'app/services/jumbotron/services/canonical/upsert_venue.rb', line 11

def call
  if venue_input.nil?
    context.venue = nil
    return
  end

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

  venue = resolve_venue(identity)

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

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