Skip to content

Commit

Permalink
feat: add is_admin field to staff view (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm authored Feb 2, 2024
1 parent 3896ffa commit b8cefc5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/safira_web/controllers/auth_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ defmodule SafiraWeb.AuthJSON do
|> Map.merge(CompanyView.render("company.json", company: company))
end

def data(%{user: %{type: "staff"}} = user) do
def data(%{user: %{type: "staff", staff: staff}} = user) do
user_data(user)
|> Map.merge(%{is_admin: staff.is_admin})
end

defp user_data(%{user: user}) do
Expand Down
5 changes: 3 additions & 2 deletions test/safira_web/controllers/auth_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule SafiraWeb.AuthControllerTest do
end

test "when user is a staff", %{user: user} do
insert(:staff, user: user)
insert(:staff, is_admin: false, user: user)

%{conn: conn, user: _user} = api_authenticate(user)

Expand All @@ -72,7 +72,8 @@ defmodule SafiraWeb.AuthControllerTest do
expected_user = %{
"email" => user.email,
"id" => user.id,
"type" => "staff"
"type" => "staff",
"is_admin" => false
}

assert json_response(conn, 200) == expected_user
Expand Down

0 comments on commit b8cefc5

Please sign in to comment.