diff --git a/lib/safira/accounts/accounts.ex b/lib/safira/accounts/accounts.ex index dd0e1a31..626fa6d8 100644 --- a/lib/safira/accounts/accounts.ex +++ b/lib/safira/accounts/accounts.ex @@ -257,9 +257,10 @@ defmodule Safira.Accounts do join: a in assoc(r, :attendee), preload: [attendee: a] ) - |> Enum.map(fn x -> x.attendee end) + |> Enum.map(fn x -> x.attendee |> Repo.preload(:user) end) else Repo.all(Attendee) + |> Repo.preload(:user) end end diff --git a/lib/safira/contest/contest.ex b/lib/safira/contest/contest.ex index 9a5dd3fd..672033e8 100644 --- a/lib/safira/contest/contest.ex +++ b/lib/safira/contest/contest.ex @@ -56,7 +56,7 @@ defmodule Safira.Contest do def get_badge_preload!(id) do Repo.get!(Badge, id) - |> Repo.preload(:attendees) + |> Repo.preload(attendees: [:user]) end def get_badge_description(description) do diff --git a/lib/safira_web/views/attendee_view.ex b/lib/safira_web/views/attendee_view.ex index 3cb05573..4ea8ba92 100644 --- a/lib/safira_web/views/attendee_view.ex +++ b/lib/safira_web/views/attendee_view.ex @@ -73,6 +73,7 @@ defmodule SafiraWeb.AttendeeView do %{ id: attendee.id, nickname: attendee.nickname, + email: attendee.user.email, name: attendee.name, course: attendee.course_id, avatar: Avatar.url({attendee.avatar, attendee}, :original), @@ -86,6 +87,7 @@ defmodule SafiraWeb.AttendeeView do %{ id: attendee.id, nickname: attendee.nickname, + email: attendee.user.email, name: attendee.name, course: attendee.course_id, avatar: Avatar.url({attendee.avatar, attendee}, :original), diff --git a/test/safira/accounts_test.exs b/test/safira/accounts_test.exs index 7926ae53..df95555b 100644 --- a/test/safira/accounts_test.exs +++ b/test/safira/accounts_test.exs @@ -495,7 +495,7 @@ defmodule Safira.AccountsTest do attendee |> forget(:user) - assert Accounts.list_company_attendees(company.id) == [attendee] + assert Accounts.list_company_attendees(company.id) == [attendee |> Repo.preload(:user)] end test "multiple attendees" do @@ -513,7 +513,10 @@ defmodule Safira.AccountsTest do attendee2 |> forget(:user) - assert Accounts.list_company_attendees(company.id) == [attendee1, attendee2] + assert Accounts.list_company_attendees(company.id) == [ + attendee1 |> Repo.preload(:user), + attendee2 |> Repo.preload(:user) + ] end test "attendee redeemed another Bronze company's badge" do @@ -536,7 +539,7 @@ defmodule Safira.AccountsTest do attendee1 |> forget(:user) - assert Accounts.list_company_attendees(company.id) == [attendee1] + assert Accounts.list_company_attendees(company.id) == [attendee1 |> Repo.preload(:user)] end end diff --git a/test/safira_web/controllers/attendee_controller_test.exs b/test/safira_web/controllers/attendee_controller_test.exs index f8302b37..398b4dfa 100644 --- a/test/safira_web/controllers/attendee_controller_test.exs +++ b/test/safira_web/controllers/attendee_controller_test.exs @@ -183,7 +183,8 @@ defmodule SafiraWeb.AttendeeControllerTest do "id" => attendee.id, "name" => attendee.name, "nickname" => "john_doe123", - "token_balance" => 0 + "token_balance" => 0, + "email" => attendee.user.email } assert json_response(conn, 200)["data"] == expected_attendee diff --git a/test/safira_web/controllers/company_controller_test.exs b/test/safira_web/controllers/company_controller_test.exs index 9b8d837b..f90c3d64 100644 --- a/test/safira_web/controllers/company_controller_test.exs +++ b/test/safira_web/controllers/company_controller_test.exs @@ -112,6 +112,7 @@ defmodule SafiraWeb.CompanyControllerTest do %{ "id" => attendee.id, "nickname" => attendee.nickname, + "email" => attendee.user.email, "name" => attendee.name, "avatar" => nil, "cv" => nil, @@ -143,6 +144,7 @@ defmodule SafiraWeb.CompanyControllerTest do %{ "id" => attendee1.id, "nickname" => attendee1.nickname, + "email" => attendee1.user.email, "name" => attendee1.name, "course" => nil, "avatar" => nil, @@ -153,6 +155,7 @@ defmodule SafiraWeb.CompanyControllerTest do %{ "id" => attendee2.id, "nickname" => attendee2.nickname, + "email" => attendee2.user.email, "name" => attendee2.name, "course" => nil, "avatar" => nil, @@ -194,6 +197,7 @@ defmodule SafiraWeb.CompanyControllerTest do %{ "id" => attendee1.id, "nickname" => attendee1.nickname, + "email" => attendee1.user.email, "name" => attendee1.name, "course" => nil, "avatar" => nil,