From 165c0912b435d288ea1d44d623cc05c9a1da4907 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Tue, 6 Feb 2024 15:00:01 +0000 Subject: [PATCH 1/2] fix: attendees with user as nil --- lib/safira/accounts/accounts.ex | 4 +++- lib/safira/contest/contest.ex | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/safira/accounts/accounts.ex b/lib/safira/accounts/accounts.ex index 69da1320..7662cc41 100644 --- a/lib/safira/accounts/accounts.ex +++ b/lib/safira/accounts/accounts.ex @@ -257,7 +257,9 @@ defmodule Safira.Accounts do join: a in assoc(r, :attendee), preload: [attendee: a] ) - |> Enum.map(fn x -> x.attendee |> Repo.preload(:user) end) + |> Enum.map(fn x -> x.attendee end) + |> Enum.filter(fn x -> not is_nil(x.user_id) end) + |> Enum.map(fn x -> Repo.preload(x, :user) end) else Repo.all(from a in Attendee, where: not is_nil(a.user_id)) |> Repo.preload(:user) diff --git a/lib/safira/contest/contest.ex b/lib/safira/contest/contest.ex index 2766650b..083a62aa 100644 --- a/lib/safira/contest/contest.ex +++ b/lib/safira/contest/contest.ex @@ -57,6 +57,7 @@ defmodule Safira.Contest do def get_badge_preload!(id) do Repo.get!(Badge, id) |> Repo.preload(attendees: [:user]) + |> Enum.map(fn b -> Enum.filter(b.attendees, fn x -> not is_nil(x.user_id) end) end) end def get_badge_description(description) do From 8ff3b5bd856f921cc767389184f53e66b922d510 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Tue, 6 Feb 2024 15:07:44 +0000 Subject: [PATCH 2/2] fix: tests --- lib/safira/contest/contest.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/safira/contest/contest.ex b/lib/safira/contest/contest.ex index 083a62aa..5a9473a0 100644 --- a/lib/safira/contest/contest.ex +++ b/lib/safira/contest/contest.ex @@ -57,7 +57,7 @@ defmodule Safira.Contest do def get_badge_preload!(id) do Repo.get!(Badge, id) |> Repo.preload(attendees: [:user]) - |> Enum.map(fn b -> Enum.filter(b.attendees, fn x -> not is_nil(x.user_id) end) end) + |> Map.update!(:attendees, fn x -> Enum.filter(x, fn x -> not is_nil(x.user_id) end) end) end def get_badge_description(description) do