Skip to content

Commit

Permalink
additional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vkghub committed Jan 22, 2025
1 parent 9e39b2c commit 98866bf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/domain/operations/families/create_member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def build_family_member(person, family)
def build_relationship(person, family, relationship_kind)
primary_person = family.primary_person

primary_person.build_or_update_relationship_with(person, relationship_kind) if primary_person.present?
primary_person.ensure_relationship_with(person, relationship_kind) if primary_person.present?
Success()
rescue StandardError => e
Failure("Relationship creation failed: #{e}")
Expand Down
2 changes: 1 addition & 1 deletion app/domain/operations/families/update_member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def build_relationship(person, family, relationship_kind)

existing_relationship = primary_person.person_relationships.where(kind: relationship_kind, relative_id: BSON::ObjectId(person.id.to_s)).first
return Success() if existing_relationship
primary_person.build_or_update_relationship_with(person, relationship_kind)
primary_person.ensure_relationship_with(person, relationship_kind)
Success()
rescue StandardError => e
Failure("Relationship creation failed: #{e}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def create_or_update(applicant_result, values)
applicant.callback_update = true

if applicant.save
@application.ensure_relationship_with_primary(applicant, values.to_h[:relationship], callback_update: true) unless applicant.is_primary_applicant
@application.ensure_relationship_with_primary(applicant, values.to_h[:relationship], {callback_update: true}) unless applicant.is_primary_applicant
@application.save!

Success(applicant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ def self.all_aasm_states
aasm.states.map(&:name)
end

def ensure_relationship_with_primary(applicant, relation_kind, callback_update: false)
add_or_update_relationships(applicant, primary_applicant, relation_kind, callback_update: callback_update)
def ensure_relationship_with_primary(applicant, relation_kind, opts = {})
add_or_update_relationships(applicant, primary_applicant, relation_kind, opts)
end

def self.families_with_latest_determined_outstanding_verification
Expand All @@ -302,18 +302,18 @@ def self.families_with_latest_determined_outstanding_verification

# Creates both relationships A to B, and B to A.
# This way we do not have to call two methods to create relationships
def add_or_update_relationships(applicant, applicant2, relation_kind, callback_update: false)
update_or_build_relationship(applicant, applicant2, relation_kind, callback_update: callback_update)
def add_or_update_relationships(applicant, applicant2, relation_kind, opts = {})
update_or_build_relationship(applicant, applicant2, relation_kind, opts)
inverse_relationship_kind = ::FinancialAssistance::Relationship::INVERSE_MAP[relation_kind]
update_or_build_relationship(applicant2, applicant, inverse_relationship_kind, callback_update: callback_update) if inverse_relationship_kind.present?
update_or_build_relationship(applicant2, applicant, inverse_relationship_kind, opts) if inverse_relationship_kind.present?
end

def update_or_build_relationship(applicant, relative, relation_kind, callback_update: false)
def update_or_build_relationship(applicant, relative, relation_kind, opts = {})
return if applicant.blank? || relative.blank? || relation_kind.blank?
return if applicant == relative

relationship = relationships.where(applicant_id: applicant.id, relative_id: relative.id).first
relationship.callback_update = callback_update
relationship.callback_update = opts[:callback_update] if opts[:callback_update].present?
if relationship.present?
# Update relationship object only if the existing RelationshipKind is different from the incoming RelationshipKind.
relationship.update(kind: relation_kind) if relationship.kind != relation_kind
Expand Down

0 comments on commit 98866bf

Please sign in to comment.