-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify auth controller (#367)
- Loading branch information
Showing
4 changed files
with
66 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,43 @@ | ||
defmodule SafiraWeb.AuthJSON do | ||
@moduledoc false | ||
|
||
alias Safira.Avatar | ||
alias SafiraWeb.AttendeeView | ||
alias SafiraWeb.CompanyView | ||
|
||
def data(%{user: user}) do | ||
%{ | ||
id: user.id, | ||
email: user.email, | ||
type: user.type | ||
} | ||
def signup_response(%{ | ||
jwt: jwt, | ||
discord_association_code: discord_association_code | ||
}) do | ||
%{jwt: jwt, discord_association_code: discord_association_code} | ||
end | ||
|
||
def is_registered(%{is_registered: value}) do | ||
%{is_registered: value} | ||
def data(%{user: %{type: "attendee", attendee: attendee}} = user) do | ||
user_data(user) | ||
|> Map.merge(AttendeeView.render("attendee.json", attendee: attendee)) | ||
end | ||
|
||
def attendee(%{user: user}) do | ||
%{ | ||
id: user.attendee.id, | ||
nickname: user.attendee.nickname, | ||
name: user.attendee.name, | ||
avatar: Avatar.url({user.attendee.avatar, user.attendee}, :original), | ||
email: user.email | ||
} | ||
def data(%{user: %{type: "company", company: company}} = user) do | ||
user_data(user) | ||
|> Map.merge(CompanyView.render("company.json", company: company)) | ||
end | ||
|
||
def company(%{user: user}) do | ||
def data(%{user: %{type: "staff"}} = user) do | ||
user_data(user) | ||
end | ||
|
||
defp user_data(%{user: user}) do | ||
%{ | ||
id: user.company.id, | ||
name: user.company.name, | ||
id: user.id, | ||
email: user.email, | ||
sponsorship: user.company.sponsorship, | ||
badge_id: user.company.badge_id | ||
type: user.type | ||
} | ||
end | ||
|
||
def jwt(%{jwt: jwt}) do | ||
%{jwt: jwt} | ||
def is_registered(%{is_registered: value}) do | ||
%{is_registered: value} | ||
end | ||
|
||
def signup_response(%{ | ||
jwt: jwt, | ||
discord_association_code: discord_association_code | ||
}) do | ||
%{jwt: jwt, discord_association_code: discord_association_code} | ||
def jwt(%{jwt: jwt}) do | ||
%{jwt: jwt} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters