summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-09-14 14:15:59 +0200
committerpdp8 <pdp8@pdp8.info>2023-09-14 14:15:59 +0200
commit49de4bbdf6d68fef2133f1399131286decae3039 (patch)
tree3d232ca4447ffd9142801d1bd31e35fe6471be5b
parenteea88e8022d3fd3c46401e1a297ebd7318c3c7b1 (diff)
update_collection fixed
-rw-r--r--helpers.rb5
1 files 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