mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-23 23:35:00 +08:00
Create step orderable element for step_text when creating a step via the API [SCI-8907]
This commit is contained in:
parent
67a8729b41
commit
88b7befbcd
1 changed files with 11 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue