Skip to content

Commit

Permalink
Uses keyword args for create person from P2P params method
Browse files Browse the repository at this point in the history
  • Loading branch information
acherukuri committed Sep 25, 2020
1 parent a0bb4e8 commit 0ca77df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 5 additions & 1 deletion app/controllers/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def create

contribution = Listing.find(params[:contribution_id])
ActiveRecord::Base.transaction do
Person.create_from_peer_to_peer_params!(current_user, peer_to_peer_match_params) if current_user.person.blank?
if current_user.person.blank?
Person.create_from_peer_to_peer_params!(current_user, name: peer_to_peer_match_params[:peer_alias],
preferred_contact_method_id: peer_to_peer_match_params[:preferred_contact_method_id],
contact_info: peer_to_peer_match_params[:preferred_contact_details])
end
Match.create_match_for_contribution!(contribution, current_user)
contribution.matched!
end
Expand Down
1 change: 1 addition & 0 deletions app/models/match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def self.follow_up_status(follow_up_status)
result
end

# FIXME: extract into an interactor
def self.create_match_for_contribution!(contribution, current_user)
match_params = if contribution.ask?
{ receiver: contribution, provider: create_offer_for_ask!(contribution, current_user) }
Expand Down
19 changes: 9 additions & 10 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ class Person < ApplicationRecord

validate :preferred_contact_method_present!

def self.create_from_peer_to_peer_params!(current_user, peer_to_peer_params)
contact_method = ContactMethod.find(peer_to_peer_params[:preferred_contact_method_id])
contact_method_details = if contact_method.name == "Email"
{ email: peer_to_peer_params[:preferred_contact_details] }
else
{ phone: peer_to_peer_params[:preferred_contact_details] }
end

person_params = { name: peer_to_peer_params[:peer_alias],
# FIXME: extract into an interactor
def self.create_from_peer_to_peer_params!(current_user, name:, preferred_contact_method_id:, contact_info:)
contact_method = ContactMethod.find(preferred_contact_method_id)
person_params = { name: name,
preferred_contact_method: contact_method,
user: current_user }
create!(person_params.merge(contact_method_details))

contact_method_name = contact_method.name == "Email" ? :email : :phone
person_params[contact_method_name] = contact_info

create!(person_params)
end

def name_and_email
Expand Down

0 comments on commit 0ca77df

Please sign in to comment.