Method: Cortex::CreateContentItemTransaction#process

Defined in:
app/transactions/cortex/create_content_item_transaction.rb

#process(input) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/transactions/cortex/create_content_item_transaction.rb', line 17

def process(input)
  if input.content_item
    content_item = input.content_item
  else
    content_item = ContentItem.new
    field_items_attributes(input.content_item_params).each do |_key, field_item_attributes|
      field_item_attributes.delete('id')
      content_item.field_items << NewFieldItemTransaction.new.call(field_item_attributes).value!
    end

    content_item.attributes = input.content_item_params.except('field_items_attributes')
  end

  content_item.tenant = input.current_user.active_tenant # TODO: In future, grab from form/route, rather than current_user + perform authorization checks

  Success(content_item)
end