From 2291da1c176c5d768fd2cc4c7abb6b02f0e84e9a Mon Sep 17 00:00:00 2001 From: shibao Date: Fri, 10 Sep 2021 00:19:46 -0400 Subject: [PATCH] add list user functions --- lib/cannery/accounts.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/cannery/accounts.ex b/lib/cannery/accounts.ex index 941bb9f5..0a8ee8aa 100644 --- a/lib/cannery/accounts.ex +++ b/lib/cannery/accounts.ex @@ -59,6 +59,21 @@ defmodule Cannery.Accounts do """ def get_user!(id), do: Repo.get!(User, id) + @spec list_users_by_role(atom()) :: [User.t()] + def list_users_by_role(role) do + Repo.all(from u in User, where: u.role == ^role) + end + + @spec list_all_users(boolean()) :: [User.t()] + def list_all_users(confirmed_users_only \\ true) do + if confirmed_users_only do + from u in User, where: u.confirmed_at + else + User + end + |> Repo.all() + end + ## User registration @doc """