From f5f66bd95f86e5f85f4ef3fab5a7453c49c1f61f Mon Sep 17 00:00:00 2001 From: f Date: Thu, 26 Oct 2023 16:46:23 -0300 Subject: [PATCH] fix: reordenar --- app/services/post_service.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 6c10b044..91d8b8f6 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -67,6 +67,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do post end + # @todo Eliminar relaciones def destroy post.destroy! @@ -82,7 +83,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do # { uuid => 2, uuid => 1, uuid => 0 } def reorder 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| next unless post.attribute? :order @@ -98,8 +99,11 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do return if files.empty? # TODO: Implementar transacciones! - posts.save_all(validate: false) && - commit(action: :reorder, add: files) + posts.map do |post| + post.save(validate: false) + end + + commit(action: :reorder, add: files) end private