scinote-web/app/controllers/concerns/api/service/reorder_validation.rb
artoscinote dd27fadd98
Add step reordering and step element reordering service endpoints to API [SCI-6891][SCI-6892] (#4179)
* Add step reordering service endpoint to API [SCI-6891]

* Generalize reorder validation [SCI-6891]

* Add endpoint for reordering step elements, fix issues [SCI-6892]

* Add appropriate serializers [SCI-6891][SCI-6892]

* Add step elements to step serializer [SCI-6891]

* Simplify routes, add locking [SCI-6891]
2022-07-12 10:13:47 +02:00

16 lines
480 B
Ruby

# frozen_string_literal: true
module Api
module Service
module ReorderValidation
extend ActiveSupport::Concern
def reorder_params_valid?(collection, reorder_params)
# contains all collection ids, positions have values from 0 to number of items in collection - 1
collection.order(:id).pluck(:id) == reorder_params.pluck(:id).sort &&
reorder_params.pluck(:position).sort == (0...reorder_params.length).to_a
end
end
end
end