mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-17 06:35:14 +08:00
dd27fadd98
* 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]
16 lines
480 B
Ruby
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
|