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
|
# File 'app/services/jumbotron/services/canonical/ensure_bookmaker.rb', line 11
def call
existing = find_identity
bookmaker = if existing&.target.is_a?(Bookmaker)
update_existing!(existing.target)
else
create_new!
end
attach = AttachProviderIdentities.call(target: bookmaker, refs: [identity])
unless attach.success?
context.fail!(application_error: attach.errors.first)
return
end
context.bookmaker = bookmaker
context.created = existing.nil?
rescue ActiveRecord::RecordNotUnique
recovered = find_identity
context.bookmaker = update_existing!(recovered.target)
context.created = false
rescue ActiveRecord::RecordInvalid => e
context.fail!(
application_error: Jumbotron::Errors::Canonical::MutationFailedError.new(
details: { message: e.message }
)
)
end
|