From 49de4bbdf6d68fef2133f1399131286decae3039 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Thu, 14 Sep 2023 14:15:59 +0200 Subject: update_collection fixed --- helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/helpers.rb b/helpers.rb index adb0b16..89ce7d4 100644 --- a/helpers.rb +++ b/helpers.rb @@ -106,13 +106,14 @@ helpers do collection = JSON.parse(json) objects.each do |object| id = object['id'] || object - if action == 'add' + if action == 'delete' collection['orderedItems'].delete_if { |o| o['id'] == id or o == id } - elsif action == 'delete' + elsif action == 'add' ids = collection['orderedItems'].collect { |i| i['id'] } collection['orderedItems'] << object unless ids.include?(id) or collection['orderedItems'].include?(id) end end + collection['orderedItems'].uniq! collection['totalItems'] = collection['orderedItems'].size f.rewind f.puts collection.to_json -- cgit v1.2.3