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: '', **_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 — target a specific stage (required for stage submit/close-out) submit: Boolean — submit the stage (triggers task transitions server-side) publish: Boolean — publish a draft page show_hidden_data: Boolean — include hidden data in the mutation response task: Hash — raw page-task command, passed through verbatim. Variants: { completePageTask: { forcedComplete:, signOff:, notes: } } — complete the page task { reviewPageTask: { signOff:, notes: } } — sign off / annotate a review task complete_page_task: Boolean|Hash — sugar for task: { completePageTask: ... }. true → { completePageTask: {} } (bare submit, no inline review). Hash → inline CompletePageInput fields (snake_case keys): { sign_off:, forced_complete:, notes: } → { completePageTask: { signOff:, forcedComplete:, notes: } }. Use { sign_off: true } to submit AND sign-off in ONE call — this advances a stage whose config has a review task (the server auto-approves the review inline). Distinct from the sign_off:/review_notes: sugar below, which targets reviewPageTask (the separate review-approval path). sign_off: Boolean — sugar: task: { reviewPageTask: { signOff: ... } } review_notes: String — sugar: adds notes: to the reviewPageTask location_ids: [ID] — set page locations (PageInput.locations); the model's locations embed is read_only, so this is the way to write them client_mutation_id: String



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ecoportal/api/graphql/input/page/update.rb', line 41

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: '', **_kargs)
  task = resolve_task(task, complete_page_task, sign_off, review_notes)
  require_stage!(stage_id, submit, task)
  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)

  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