Create step orderable element for step_text when creating a step via the API [SCI-8907]

This commit is contained in:
wandji20 2023-08-01 19:55:36 +01:00
parent 67a8729b41
commit 88b7befbcd

View file

@ -30,15 +30,23 @@ module Api
def create
raise PermissionError.new(Protocol, :create) unless can_manage_protocol_in_module?(@protocol)
step = @protocol.steps.create!(
step = @protocol.steps.build(
step_params.except(:description)
.merge!(completed: false,
user: current_user,
position: @protocol.number_of_steps,
last_modified_by_id: current_user.id)
)
step.step_texts.create!(text: step_params[:description]) if step_params[:description]
ActiveRecord::Base.transaction do
step.save!
if step_params[:description]
step_text = step.step_texts.build(text: step_params[:description])
step.step_orderable_elements.create!(
position: 0,
orderable: step_text
)
end
end
render jsonapi: step, serializer: StepSerializer, status: :created
end