Skip to content

Commit

Permalink
fix API contract
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnIckler committed Jul 24, 2024
1 parent 7782bd3 commit 0c65d4d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def do_import
delete_params = []
registrations.filter { |r| r.accepted? }.each do |registration|
unless emails.include?(registration.user.email)
delete_params << { attendee_id: registration.attendee_id, competing_status: "deleted", acting_id: current_user.id, acting_type: "user" }
delete_params << { attendee_id: registration.attendee_id, user_id: registration.user.id, competing_status: "deleted", actor_id: current_user.id, actor_type: "user" }
end
end
registration_rows.each do |registration_row|
Expand All @@ -174,20 +174,20 @@ def do_import
events = competition.competition_events.each_with_object([]) do |competition_event, signed_up_events|
value = registration_row[competition_event.event_id.to_sym]
if value == "1"
signed_up_events >> competition_event.id
signed_up_events << competition_event.event_id
elsif value != "0"
raise I18n.t("registrations.import.errors.invalid_event_column", value: value, column: competition_event.event_id)
end
end
if registration.nil?
create_params << { attendee_id: "#{competition.id}-#{user.id}", competing_status: "accepted", acting_id: current_user.id, acting_type: "user", event_ids: events }
create_params << { attendee_id: "#{competition.id}-#{user.id}", user_id: user.id, competing_status: "accepted", actor_id: current_user.id, actor_type: "user", event_ids: events }
else
update_params << { attendee_id: registration.attendee_id, competing_status: "accepted", acting_id: current_user.id, acting_type: "user", event_ids: events }
update_params << { attendee_id: registration.attendee_id, user_id: user.id, competing_status: "accepted", actor_id: current_user.id, actor_type: "user", event_ids: events }
end
end
import_response = Microservices::Registrations.import_registrations(competition.id, { create: create_params, update: update_params, delete: delete_params })
if import_response.errors.any?
raise import_response.errors.join(', ')
unless import_response[:errors].nil?
raise import_response[:errors].join(', ')
end
else
ActiveRecord::Base.transaction do
Expand Down Expand Up @@ -225,6 +225,7 @@ def do_import
redirect_to competition_registrations_import_url(competition)
rescue StandardError => e
flash[:danger] = e.to_s
puts e.backtrace
redirect_to competition_registrations_import_url(competition)
end

Expand Down

0 comments on commit 0c65d4d

Please sign in to comment.