summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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