This commit is contained in:
@@ -12,7 +12,7 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
|
||||
end
|
||||
|
||||
actions do
|
||||
defaults [:read, :update, :destroy]
|
||||
defaults [:read, :destroy]
|
||||
|
||||
create :create do
|
||||
primary? true
|
||||
@@ -20,7 +20,8 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
|
||||
argument :author_id, :uuid
|
||||
|
||||
change fn changeset, _ ->
|
||||
author_id = changeset.arguments.author_id
|
||||
author_id =
|
||||
Map.get(changeset.arguments, :author_id, nil)
|
||||
|
||||
if author_id != nil do
|
||||
{:ok, author} = DecentralisedBookIndex.Metadata.get_author_by_id(author_id)
|
||||
@@ -37,6 +38,24 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
|
||||
get? true
|
||||
filter expr(id == ^arg(:id))
|
||||
end
|
||||
|
||||
update :update do
|
||||
primary? true
|
||||
accept [:order, :role]
|
||||
argument :author_id, :uuid
|
||||
|
||||
change fn changeset, _ ->
|
||||
author_id = changeset.arguments.author_id
|
||||
|
||||
if author_id != nil do
|
||||
{:ok, author} = DecentralisedBookIndex.Metadata.get_author_by_id(author_id)
|
||||
|
||||
Ash.Changeset.force_change_attribute(changeset, :author_id, author.id)
|
||||
else
|
||||
changeset
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
|
||||
Reference in New Issue
Block a user