order in db
This commit is contained in:
parent
0b0e1cc639
commit
7110a2db21
@ -74,7 +74,7 @@ defmodule Cannery.Accounts do
|
||||
"""
|
||||
@spec list_all_users_by_role(User.t()) :: %{String.t() => [User.t()]}
|
||||
def list_all_users_by_role(%User{role: :admin}) do
|
||||
Repo.all(User) |> Enum.group_by(fn user -> user.role end)
|
||||
Repo.all(from u in User, order_by: u.email) |> Enum.group_by(fn user -> user.role end)
|
||||
end
|
||||
|
||||
@doc """
|
||||
@ -89,7 +89,7 @@ defmodule Cannery.Accounts do
|
||||
@spec list_users_by_role(:admin | :user) :: [User.t()]
|
||||
def list_users_by_role(role) do
|
||||
role = role |> to_string()
|
||||
Repo.all(from u in User, where: u.role == ^role)
|
||||
Repo.all(from u in User, where: u.role == ^role, order_by: u.email)
|
||||
end
|
||||
|
||||
## User registration
|
||||
|
@ -19,7 +19,7 @@ defmodule Cannery.Ammo do
|
||||
"""
|
||||
@spec list_ammo_types(User.t()) :: [AmmoType.t()]
|
||||
def list_ammo_types(%User{id: user_id}),
|
||||
do: Repo.all(from at in AmmoType, where: at.user_id == ^user_id)
|
||||
do: Repo.all(from at in AmmoType, where: at.user_id == ^user_id, order_by: at.name)
|
||||
|
||||
@doc """
|
||||
Gets a single ammo_type.
|
||||
@ -163,7 +163,8 @@ defmodule Cannery.Ammo do
|
||||
Repo.all(
|
||||
from am in AmmoGroup,
|
||||
where: am.ammo_type_id == ^ammo_type_id,
|
||||
where: am.user_id == ^user_id
|
||||
where: am.user_id == ^user_id,
|
||||
order_by: am.id
|
||||
)
|
||||
end
|
||||
|
||||
@ -180,9 +181,12 @@ defmodule Cannery.Ammo do
|
||||
@spec list_ammo_groups(User.t(), include_empty :: boolean()) :: [AmmoGroup.t()]
|
||||
def list_ammo_groups(%User{id: user_id}, include_empty \\ false) do
|
||||
if include_empty do
|
||||
from am in AmmoGroup, where: am.user_id == ^user_id
|
||||
from am in AmmoGroup, where: am.user_id == ^user_id, order_by: am.id
|
||||
else
|
||||
from am in AmmoGroup, where: am.user_id == ^user_id, where: not (am.count == 0)
|
||||
from am in AmmoGroup,
|
||||
where: am.user_id == ^user_id,
|
||||
where: not (am.count == 0),
|
||||
order_by: am.id
|
||||
end
|
||||
|> Repo.all()
|
||||
end
|
||||
@ -198,7 +202,12 @@ defmodule Cannery.Ammo do
|
||||
"""
|
||||
@spec list_staged_ammo_groups(User.t()) :: [AmmoGroup.t()]
|
||||
def list_staged_ammo_groups(%User{id: user_id}) do
|
||||
Repo.all(from am in AmmoGroup, where: am.user_id == ^user_id, where: am.staged == true)
|
||||
Repo.all(
|
||||
from am in AmmoGroup,
|
||||
where: am.user_id == ^user_id,
|
||||
where: am.staged == true,
|
||||
order_by: am.id
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -20,7 +20,7 @@ defmodule Cannery.Containers do
|
||||
"""
|
||||
@spec list_containers(User.t()) :: [Container.t()]
|
||||
def list_containers(%User{id: user_id}),
|
||||
do: Repo.all(from c in Container, where: c.user_id == ^user_id)
|
||||
do: Repo.all(from c in Container, where: c.user_id == ^user_id, order_by: c.name)
|
||||
|
||||
@doc """
|
||||
Gets a single container.
|
||||
|
@ -20,7 +20,7 @@ defmodule Cannery.Invites do
|
||||
"""
|
||||
@spec list_invites(User.t()) :: [Invite.t()]
|
||||
def list_invites(%User{role: :admin}) do
|
||||
Repo.all(Invite)
|
||||
Repo.all(from i in Invite, order_by: i.name)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -18,7 +18,8 @@ defmodule Cannery.Tags do
|
||||
|
||||
"""
|
||||
@spec list_tags(User.t()) :: [Tag.t()]
|
||||
def list_tags(%{id: user_id}), do: Repo.all(from t in Tag, where: t.user_id == ^user_id)
|
||||
def list_tags(%{id: user_id}),
|
||||
do: Repo.all(from t in Tag, where: t.user_id == ^user_id, order_by: t.name)
|
||||
|
||||
@doc """
|
||||
Gets a single tag.
|
||||
|
@ -138,16 +138,15 @@ defmodule CanneryWeb.InviteLive.Index do
|
||||
end
|
||||
|
||||
defp display_invites(%{assigns: %{current_user: current_user}} = socket) do
|
||||
invites = Invites.list_invites(current_user) |> Enum.sort_by(fn %{name: name} -> name end)
|
||||
invites = Invites.list_invites(current_user)
|
||||
all_users = Accounts.list_all_users_by_role(current_user)
|
||||
|
||||
admins =
|
||||
all_users
|
||||
|> Map.get(:admin, [])
|
||||
|> Enum.reject(fn %{id: user_id} -> user_id == current_user.id end)
|
||||
|> Enum.sort_by(fn %{email: email} -> email end)
|
||||
|
||||
users = all_users |> Map.get(:user, []) |> Enum.sort_by(fn %{email: email} -> email end)
|
||||
users = all_users |> Map.get(:user, [])
|
||||
socket |> assign(invites: invites, admins: admins, users: users)
|
||||
end
|
||||
end
|
||||
|
@ -132,7 +132,7 @@ msgid "must have the @ sign and no spaces"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-format, ex-autogen
|
||||
#: lib/cannery/tags.ex:39
|
||||
#: lib/cannery/tags.ex:40
|
||||
msgid "Tag not found"
|
||||
msgstr ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user