Fix nil-index crash in move_record_in_set
This commit is contained in:
@@ -165,15 +165,18 @@ defmodule MusicLibrary.RecordSets do
|
||||
)
|
||||
|> Repo.all()
|
||||
|
||||
index = Enum.find_index(items, fn i -> i.record_id == record_id end)
|
||||
case Enum.find_index(items, fn i -> i.record_id == record_id end) do
|
||||
nil ->
|
||||
:ok
|
||||
|
||||
index ->
|
||||
swap_index =
|
||||
case direction do
|
||||
:up -> index - 1
|
||||
:down -> index + 1
|
||||
end
|
||||
|
||||
if index && swap_index >= 0 && swap_index < length(items) do
|
||||
if swap_index >= 0 and swap_index < length(items) do
|
||||
item_a = Enum.at(items, index)
|
||||
item_b = Enum.at(items, swap_index)
|
||||
|
||||
@@ -187,6 +190,7 @@ defmodule MusicLibrary.RecordSets do
|
||||
|> Repo.update!()
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
{:ok, get_record_set!(record_set.id)}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user