better code style

This commit is contained in:
2025-02-15 04:04:10 +00:00
parent 2a8a1d11b8
commit 3e686fa199
32 changed files with 225 additions and 186 deletions

View File

@ -117,7 +117,7 @@ defmodule Memex.Accounts do
Multi.new()
|> Multi.one(:users_count, from(u in User, select: count(u.id), distinct: true))
|> Multi.run(:use_invite, fn _changes_so_far, _repo ->
if allow_registration?() and invite_token |> is_nil() do
if allow_registration?() and !invite_token do
{:ok, nil}
else
Invites.use_invite(invite_token)

View File

@ -22,7 +22,7 @@ defmodule Memex.Contexts do
@spec list_contexts(search :: String.t() | nil, User.t()) :: [Context.t()]
def list_contexts(search \\ nil, user)
def list_contexts(search, %{id: user_id}) when search |> is_nil() or search == "" do
def list_contexts(search, %{id: user_id}) when search in [nil, ""] do
Repo.all(from c in Context, where: c.user_id == ^user_id, order_by: c.slug)
end
@ -63,7 +63,7 @@ defmodule Memex.Contexts do
@spec list_public_contexts(search :: String.t() | nil) :: [Context.t()]
def list_public_contexts(search \\ nil)
def list_public_contexts(search) when search |> is_nil() or search == "" do
def list_public_contexts(search) when search in [nil, ""] do
Repo.all(from c in Context, where: c.visibility == :public, order_by: c.slug)
end

View File

@ -22,11 +22,11 @@ defmodule Memex.Notes do
@spec list_notes(search :: String.t() | nil, User.t()) :: [Note.t()]
def list_notes(search \\ nil, user)
def list_notes(search, %{id: user_id}) when search |> is_nil() or search == "" do
Repo.all(from n in Note, where: n.user_id == ^user_id, order_by: n.slug)
def list_notes(search, %{id: user_id}) when user_id |> is_binary() and search in [nil, ""] do
Repo.all(from n in Note, order_by: n.slug)
end
def list_notes(search, %{id: user_id}) when search |> is_binary() do
def list_notes(search, %{id: user_id}) when user_id |> is_binary() and search |> is_binary() do
trimmed_search = String.trim(search)
Repo.all(
@ -62,7 +62,7 @@ defmodule Memex.Notes do
@spec list_public_notes(search :: String.t() | nil) :: [Note.t()]
def list_public_notes(search \\ nil)
def list_public_notes(search) when search |> is_nil() or search == "" do
def list_public_notes(search) when search in [nil, ""] do
Repo.all(from n in Note, where: n.visibility == :public, order_by: n.slug)
end

View File

@ -22,7 +22,7 @@ defmodule Memex.Pipelines do
@spec list_pipelines(search :: String.t() | nil, User.t()) :: [Pipeline.t()]
def list_pipelines(search \\ nil, user)
def list_pipelines(search, %{id: user_id}) when search |> is_nil() or search == "" do
def list_pipelines(search, %{id: user_id}) when search in [nil, ""] do
Repo.all(from p in Pipeline, where: p.user_id == ^user_id, order_by: p.slug)
end
@ -62,7 +62,7 @@ defmodule Memex.Pipelines do
@spec list_public_pipelines(search :: String.t() | nil) :: [Pipeline.t()]
def list_public_pipelines(search \\ nil)
def list_public_pipelines(search) when search |> is_nil() or search == "" do
def list_public_pipelines(search) when search in [nil, ""] do
Repo.all(from p in Pipeline, where: p.visibility == :public, order_by: p.slug)
end