mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 04:46:21 +00:00
fix: reordenar
This commit is contained in:
parent
0dc3a69a93
commit
f5f66bd95f
1 changed files with 7 additions and 3 deletions
|
@ -67,6 +67,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @todo Eliminar relaciones
|
||||||
def destroy
|
def destroy
|
||||||
post.destroy!
|
post.destroy!
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
# { uuid => 2, uuid => 1, uuid => 0 }
|
# { uuid => 2, uuid => 1, uuid => 0 }
|
||||||
def reorder
|
def reorder
|
||||||
reorder = params.require(:post).permit(reorder: {})&.dig(:reorder)&.transform_values(&:to_i)
|
reorder = params.require(:post).permit(reorder: {})&.dig(:reorder)&.transform_values(&:to_i)
|
||||||
posts = site.indexed_posts(locale: locale).where(post_id: reorder.keys).map(&:post)
|
posts = site.indexed_posts.where(locale: locale, post_id: reorder.keys).map(&:post)
|
||||||
|
|
||||||
files = posts.map do |post|
|
files = posts.map do |post|
|
||||||
next unless post.attribute? :order
|
next unless post.attribute? :order
|
||||||
|
@ -98,7 +99,10 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
return if files.empty?
|
return if files.empty?
|
||||||
|
|
||||||
# TODO: Implementar transacciones!
|
# TODO: Implementar transacciones!
|
||||||
posts.save_all(validate: false) &&
|
posts.map do |post|
|
||||||
|
post.save(validate: false)
|
||||||
|
end
|
||||||
|
|
||||||
commit(action: :reorder, add: files)
|
commit(action: :reorder, add: files)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue