Skip to content

Commit

Permalink
fix: fix family summary (monicahq/chandler#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Oct 30, 2022
1 parent 2850688 commit 478d574
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function data(Contact $contact, User $user): array
->where('type', RelationshipType::TYPE_LOVE)
->get();

$loveRelationshipsCollection = self::getRelations($loveRelationships, $contact, $user);
$loveRelationshipsCollection = self::getRelations($loveRelationships, $contact);

$familyRelationshipType = $contact->vault->account->relationshipGroupTypes()
->where('type', RelationshipGroupType::TYPE_FAMILY)
Expand All @@ -41,15 +41,15 @@ public static function data(Contact $contact, User $user): array
->where('type', RelationshipType::TYPE_CHILD)
->get();

$familyRelationshipsCollection = self::getRelations($familyRelationships, $contact, $user);
$familyRelationshipsCollection = self::getRelations($familyRelationships, $contact);

return [
'family_relationships' => $familyRelationshipsCollection,
'love_relationships' => $loveRelationshipsCollection,
];
}

private static function getRelations(EloquentCollection $collection, Contact $contact, User $user): Collection
private static function getRelations(EloquentCollection $collection, Contact $contact): Collection
{
$relationshipsCollection = collect();
$counter = 0;
Expand All @@ -70,12 +70,12 @@ private static function getRelations(EloquentCollection $collection, Contact $co
}

foreach ($relations as $relation) {
if ($relation->contact_id !== $contact->id) {
continue;
if ($relation->contact_id === $contact->id) {
$relatedContact = Contact::find($relation->related_contact_id);
} else {
$relatedContact = Contact::find($relation->contact_id);
}

$relatedContact = Contact::find($relation->related_contact_id);

$relationshipsCollection->push([
'id' => $counter,
'contact' => self::getContact($relatedContact),
Expand Down

0 comments on commit 478d574

Please sign in to comment.