Skip to content

Commit

Permalink
chore: change managers to staffs (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 authored Nov 9, 2023
1 parent 61ac89b commit b6ce036
Show file tree
Hide file tree
Showing 59 changed files with 348 additions and 349 deletions.
5 changes: 2 additions & 3 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ config :safira,
staff_code: System.get_env("DISCORD_STAFF_CODE"),
from_email: System.get_env("FROM_EMAIL") || "test@seium.com",
from_email_name: System.get_env("FROM_EMAIL_NAME") || "SEI",
roulette_cost: String.to_integer(System.get_env("ROULETTE_COST") || "10"),
roulette_cost: String.to_integer(System.get_env("ROULETTE_COST") || "20"),
roulette_tokens_min: String.to_integer(System.get_env("ROULETTE_TOKENS_MIN") || "5"),
roulette_tokens_max: String.to_integer(System.get_env("ROULETTE_TOKENS_MAX") || "20"),
token_bonus: String.to_integer(System.get_env("TOKEN_BONUS") || "10"),
Expand Down
10 changes: 5 additions & 5 deletions lib/mix/tasks/gen.managers.ex → lib/mix/tasks/gen.staffs.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Mix.Tasks.Gen.Managers do
defmodule Mix.Tasks.Gen.Staffs do
@moduledoc """
Task to generate managers
Task to generate staffs
"""

use Mix.Task
Expand All @@ -25,7 +25,7 @@ defmodule Mix.Tasks.Gen.Managers do
Mix.Task.run("app.start")

Enum.each(1..n, fn _n ->
email = Enum.join(["manager#{man_num() + 1}", @domain], "@")
email = Enum.join(["staff#{man_num() + 1}", @domain], "@")
password = random_string(8)

user = %{
Expand All @@ -34,14 +34,14 @@ defmodule Mix.Tasks.Gen.Managers do
"password_confirmation" => password
}

Accounts.create_manager(%{"user" => user})
Accounts.create_staff(%{"user" => user})

IO.puts("#{email}:#{password}")
end)
end

defp man_num do
Accounts.list_managers()
Accounts.list_staffs()
|> List.last()
|> give_num
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Mix.Tasks.Gen.ManagersFromCsv do
defmodule Mix.Tasks.Gen.StaffsFromCsv do
@shortdoc "Generates the mangers from a CSV"

@moduledoc """
Expand All @@ -7,8 +7,8 @@ defmodule Mix.Tasks.Gen.ManagersFromCsv do
and a flag ("Local"/"Remote") indicating if the file is local or remote
## Examples
$ mix gen.managers_from_csv "assets/managers_sei_exemplo.csv" "Local"
$ mix gen.managers_from_csv "https://sample.url.managers_sei_exemplo.csv" "Remote"
$ mix gen.staffs_from_csv "assets/staffs_sei_exemplo.csv" "Local"
$ mix gen.staffs_from_csv "https://sample.url.staffs_sei_exemplo.csv" "Remote"
"""

use Mix.Task
Expand Down Expand Up @@ -90,7 +90,7 @@ defmodule Mix.Tasks.Gen.ManagersFromCsv do
"password_confirmation" => password
}

Accounts.create_manager(%{"user" => user, "is_admin" => convert!(user_csv_entry.admin)})
Accounts.create_staff(%{"user" => user, "is_admin" => convert!(user_csv_entry.admin)})

IO.puts("#{email}:#{password}")
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.all.attendees.badge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Mix.Tasks.Gift.All.Attendees.Badge do
|> Enum.each(fn a ->
Contest.create_redeem(%{
attendee_id: a.id,
manager_id: 1,
staff_id: 1,
badge_id: badge_id
})
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.all.badges.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Mix.Tasks.Gift.All.Badges do

Safira.Contest.list_badges()
|> Enum.map(
&Safira.Contest.create_redeem(%{attendee_id: attendee_id, manager_id: 1, badge_id: &1.id})
&Safira.Contest.create_redeem(%{attendee_id: attendee_id, staff_id: 1, badge_id: &1.id})
)
end
end
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.all_gold.badge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Mix.Tasks.Gift.AllGold.Badge do

attendees
|> Enum.each(fn id ->
Contest.create_redeem(%{attendee_id: id, badge_id: badge_id, manager_id: 1}, :admin)
Contest.create_redeem(%{attendee_id: id, badge_id: badge_id, staff_id: 1}, :admin)
end)
end
end
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.badge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ defmodule Mix.Tasks.Gift.Badge do

defp give(attendee_id, badge_id) do
Contest.create_redeem(
%{attendee_id: attendee_id, manager_id: 1, badge_id: badge_id},
%{attendee_id: attendee_id, staff_id: 1, badge_id: badge_id},
:admin
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.badge.full.participation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule Mix.Tasks.Gift.Badge.Full.Participation do
Contest.create_redeem(
%{
attendee_id: attendee_id,
manager_id: 1,
staff_id: 1,
badge_id: badge_id
},
:admin
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.badge.participation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule Mix.Tasks.Gift.Badge.Participation do
Contest.create_redeem(
%{
attendee_id: attendee_id,
manager_id: 1,
staff_id: 1,
badge_id: badge_id
},
:admin
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.checkpoint.badge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ defmodule Mix.Tasks.Gift.Company.Checkpoint.Badge do
%{
attendee_id: a.id,
badge_id: Map.get(args, :badge_id),
manager_id: 1
staff_id: 1
}
|> create_redeem(args, a, Map.get(args, :badge))
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.checkpoint.badge.quantity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ defmodule Mix.Tasks.Gift.Quantity.Checkpoint.Badge do
%{
attendee_id: a.id,
badge_id: Map.get(args, :badge_id),
manager_id: 1
staff_id: 1
}
|> create_redeem(args, a, Map.get(args, :badge))
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.checkpoint.badge.with.redeemable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ defmodule Mix.Tasks.Gift.Company.Checkpoint.Badge.With.Redeemable do
%{
attendee_id: a.id,
badge_id: Map.get(args, :badge_id),
manager_id: 1
staff_id: 1
}
|> create_redeem(args, a, Map.get(args, :badge))
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/gift.daily.badge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule Mix.Tasks.Gift.Daily.Badge do
Contest.create_redeem(
%{
attendee_id: a.id,
manager_id: 1,
staff_id: 1,
badge_id: badge_id
},
:admin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Mix.Tasks.Govern.Managers do
defmodule Mix.Tasks.Govern.Staffs do
@moduledoc """
Task to activate all manager accounts
Task to activate all staff accounts
"""
use Mix.Task

Expand All @@ -20,8 +20,8 @@ defmodule Mix.Tasks.Govern.Managers do
defp create(email, value) do
Mix.Task.run("app.start")

Safira.Accounts.get_manager_by_email(email)
Safira.Accounts.get_staff_by_email(email)
|> List.first()
|> Safira.Accounts.update_manager(%{active: value})
|> Safira.Accounts.update_staff(%{active: value})
end
end
48 changes: 24 additions & 24 deletions lib/safira/accounts/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Safira.Accounts do

alias Safira.Accounts.Attendee
alias Safira.Accounts.Company
alias Safira.Accounts.Manager
alias Safira.Accounts.Staff
alias Safira.Accounts.User

alias Safira.Repo
Expand All @@ -22,7 +22,7 @@ defmodule Safira.Accounts do
Repo.get!(User, id)
|> Repo.preload(:attendee)
|> Repo.preload(:company)
|> Repo.preload(:manager)
|> Repo.preload(:staff)
end

def get_user_email(email) do
Expand All @@ -33,14 +33,14 @@ defmodule Safira.Accounts do
Repo.get_by!(User, email: email)
|> Repo.preload(:attendee)
|> Repo.preload(:company)
|> Repo.preload(:manager)
|> Repo.preload(:staff)
end

def get_user_preload_email(email) do
Repo.get_by(User, email: email)
|> Repo.preload(:attendee)
|> Repo.preload(:company)
|> Repo.preload(:manager)
|> Repo.preload(:staff)
end

def get_user_token(token) do
Expand Down Expand Up @@ -151,39 +151,39 @@ defmodule Safira.Accounts do
Attendee.changeset(attendee, %{})
end

def list_managers do
Repo.all(Manager)
def list_staffs do
Repo.all(Staff)
end

def get_manager!(id), do: Repo.get!(Manager, id)
def get_staff!(id), do: Repo.get!(Staff, id)

def get_manager_by_email(email) do
def get_staff_by_email(email) do
Repo.all(
from m in Manager,
from m in Staff,
join: u in assoc(m, :user),
where: u.email == ^email,
preload: [user: u]
)
end

def create_manager(attrs \\ %{}) do
%Manager{}
|> Manager.changeset(attrs)
def create_staff(attrs \\ %{}) do
%Staff{}
|> Staff.changeset(attrs)
|> Repo.insert()
end

def update_manager(%Manager{} = manager, attrs) do
manager
|> Manager.changeset(attrs)
def update_staff(%Staff{} = staff, attrs) do
staff
|> Staff.changeset(attrs)
|> Repo.update()
end

def delete_manager(%Manager{} = manager) do
Repo.delete(manager)
def delete_staff(%Staff{} = staff) do
Repo.delete(staff)
end

def change_manager(%Manager{} = manager) do
Manager.changeset(manager, %{})
def change_staff(%Staff{} = staff) do
Staff.changeset(staff, %{})
end

def list_companies do
Expand Down Expand Up @@ -233,19 +233,19 @@ defmodule Safira.Accounts do
|> Kernel.not()
end

def is_manager(conn) do
def is_staff(conn) do
get_user(conn)
|> Map.fetch!(:manager)
|> Map.fetch!(:staff)
|> is_nil
|> Kernel.not()
end

def is_admin(conn) do
manager =
staff =
get_user(conn)
|> Map.fetch(:manager)
|> Map.fetch(:staff)

case manager do
case staff do
{:error} ->
false

Expand Down
10 changes: 5 additions & 5 deletions lib/safira/accounts/manager.ex → lib/safira/accounts/staff.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Safira.Accounts.Manager do
defmodule Safira.Accounts.Staff do
@moduledoc """
A manager is a staff member who can give attendees badges and
A staff is a staff member who can give attendees badges and
deliver them prizes they win throughout the event
"""
use Ecto.Schema
Expand All @@ -9,7 +9,7 @@ defmodule Safira.Accounts.Manager do
alias Safira.Accounts.User
alias Safira.Contest.Redeem

schema "managers" do
schema "staffs" do
field :active, :boolean, default: true
field :is_admin, :boolean, default: false

Expand All @@ -19,8 +19,8 @@ defmodule Safira.Accounts.Manager do
timestamps()
end

def changeset(manager, attrs) do
manager
def changeset(staff, attrs) do
staff
|> cast(attrs, [:active, :is_admin])
|> cast_assoc(:user)
|> validate_required([:active, :is_admin])
Expand Down
4 changes: 2 additions & 2 deletions lib/safira/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ defmodule Safira.Accounts.User do

alias Safira.Accounts.Attendee
alias Safira.Accounts.Company
alias Safira.Accounts.Manager
alias Safira.Accounts.Staff

schema "users" do
field :email, :string
field :password_hash, :string
field :ban, :boolean, default: false

has_one :attendee, Attendee, on_delete: :delete_all
has_one :manager, Manager, on_delete: :delete_all
has_one :staff, Staff, on_delete: :delete_all
has_one :company, Company, on_delete: :delete_all

field :reset_password_token, :string
Expand Down
Loading

0 comments on commit b6ce036

Please sign in to comment.