Class: Ecoportal::API::GraphQL::Input::Page::Update

Inherits:
Logic::Input
  • Object
show all
Defined in:
lib/ecoportal/api/graphql/input/page/update.rb

Constant Summary collapse

PAGE_FIELD_KEYS =
Input::Page::PAGE_FIELD_KEYS

Class Method Summary collapse

Class Method Details

.from_model(model, stage_id: nil, submit: nil, publish: nil, show_hidden_data: nil, task: nil, complete_page_task: false, sign_off: nil, review_notes: nil, location_ids: nil, client_mutation_id: SecureRandom.uuid, **_kargs) ⇒ Object

Builds UpdatePageInput from a page model. Returns nil when there are no changes and no operation is requested. patchVer is always included when present (required for concurrency control).

Options:

stage_id:           ID      


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ecoportal/api/graphql/input/page/update.rb', line 68

def from_model(model, stage_id: nil, submit: nil, publish: nil, show_hidden_data: nil,
               task: nil, complete_page_task: false, sign_off: nil, review_notes: nil,
               location_ids: nil, client_mutation_id: SecureRandom.uuid, **_kargs)
  task = resolve_task(task, complete_page_task, sign_off, review_notes)
  page_input = (model.as_update || {}).slice(*PAGE_FIELD_KEYS)
  # Page locations are read_only on the model (excluded from the as_update diff),
  # so set them explicitly here → PageInput.locations = [LocationInput{ id }].
  page_input = page_input.merge(locations: Array(location_ids).map { |lid| { id: lid } }) unless location_ids.nil?
  data_fields = build_data_fields(model)
  stage_id  ||= derive_stage_id(model, data_fields)
  require_stage!(stage_id, submit, task)

  no_changes = page_input.empty? && data_fields.empty?
  no_op      = publish.nil? && submit.nil? && stage_id.nil? && task.nil?
  return nil if no_changes && no_op

  operation = {
    stageId:          stage_id,
    submit:           submit,
    publish:          publish,
    showHiddenData:   show_hidden_data,
    task:             task,
    clientMutationId: (client_mutation_id.to_s.empty? ? nil : client_mutation_id)
  }
  build_input(model, page_input, data_fields, operation)
end