Skip to content

Commit

Permalink
feat: make categorize_detour/2 public
Browse files Browse the repository at this point in the history
  • Loading branch information
firestack committed Sep 26, 2024
1 parent 8d9d21d commit 80b04a0
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/skate/detours/detours.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,25 @@ defmodule Skate.Detours.Detours do

@type detour_type :: :active | :draft | :past

@doc """
Takes a `Skate.Detours.Db.Detour` struct and a `Skate.Settings.Db.User` id
and returns a `t:detour_type/0` based on the state of the detour.
returns `nil` if the state is indeterminate.
"""
@spec categorize_detour(map(), integer()) :: detour_type
defp categorize_detour(
%{state: %{"value" => %{"Detour Drawing" => %{"Active" => _}}}},
_user_id
),
do: :active
def categorize_detour(
%{state: %{"value" => %{"Detour Drawing" => %{"Active" => _}}}},
_user_id
),
do: :active

defp categorize_detour(%{state: %{"value" => %{"Detour Drawing" => "Past"}}}, _user_id),
def categorize_detour(%{state: %{"value" => %{"Detour Drawing" => "Past"}}}, _user_id),
do: :past

defp categorize_detour(_detour_context, nil = _user_id), do: :draft
defp categorize_detour(%{author_id: author_id}, user_id) when author_id == user_id, do: :draft
defp categorize_detour(_, _), do: nil
def categorize_detour(_detour_context, nil = _user_id), do: :draft
def categorize_detour(%{author_id: author_id}, user_id) when author_id == user_id, do: :draft
def categorize_detour(_, _), do: nil

@doc """
Gets a single detour.
Expand Down

0 comments on commit 80b04a0

Please sign in to comment.