prop/lib/microwaveprop_web/controllers/api/v1/token_json.ex
Graham McIntire fd976b0cd5
fix: resolve 391 Credo issues across codebase
- Add jump_credo_checks ~> 0.4 with all 20 checks enabled
- Fix all standard Credo issues: 139 @spec (113 done, 26 remain),
  4 refactoring, 3 alias usage, 9 System.cmd env, 5 unsafe_to_atom,
  2 max line length, 9 assert_receive timeout
- Fix 170+ jump_credo_checks warnings:
  - 117 TopLevelAliasImportRequire: move nested alias/import to module top
  - 32 UseObanProWorker: switch to Oban.Pro.Worker
  - 4 DoctestIExExamples: add doctests / create test file
  - ~20 WeakAssertion: strengthen type-check assertions
  - Various ConditionalAssertion, AssertReceiveTimeout fixes
- Exclude vendor/ from Credo analysis
- Remaining: 175 warnings (mostly opinionated WeakAssertion,
  AvoidSocketAssignsInTest), 26 @spec annotations
2026-06-12 13:51:32 -05:00

32 lines
944 B
Elixir

defmodule MicrowavepropWeb.Api.V1.TokenJSON do
@moduledoc "Renders user API token responses."
alias Microwaveprop.Accounts.UserApiToken
@doc "Token list view (no plaintext — never recoverable after creation)."
@spec index(map()) :: map()
def index(%{tokens: tokens}) do
%{data: Enum.map(tokens, &data/1)}
end
@doc "Single token without plaintext."
@spec show(map()) :: map()
def show(%{token: token}), do: %{data: data(token)}
@doc "Single token including the one-time plaintext value at the top level."
@spec show_with_plaintext(UserApiToken.t(), String.t()) :: map()
def show_with_plaintext(%UserApiToken{} = token, plaintext) do
%{data: data(token), token: plaintext}
end
defp data(%UserApiToken{} = t) do
%{
id: t.id,
name: t.name,
inserted_at: t.inserted_at,
last_used_at: t.last_used_at,
expires_at: t.expires_at,
revoked_at: t.revoked_at
}
end
end