vol1ura/Sat_9am_5km

View on GitHub
app/jobs/add_athlete_to_result_job.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

class AddAthleteToResultJob < ApplicationJob
  queue_as :default

  discard_on ActiveRecord::RecordInvalid

  def perform(activity_id, code, position)
    activity = Activity.find activity_id
    athlete = Athlete.find_or_scrape_by_code! code.delete('A').to_i
    result = activity.results.find_or_initialize_by position: position.delete('P').to_i
    result = activity.results.new result.as_json(only: %i[total_time position]) if result.athlete_id

    result.without_auditing { result.update! athlete: }
  end
end