Module: Eco::API::UseCases::GraphQL::Helpers::Location::Command::EndPoints

Includes:
Base, Optimizations, Language::AuxiliarLogger
Included in:
Eco::API::UseCases::GraphQL::Helpers::Location::Command
Defined in:
lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb,
lib/eco/api/usecases/graphql/helpers/location/command/end_points/optimizations.rb

Defined Under Namespace

Modules: Optimizations

Constant Summary

Constants included from Optimizations

Optimizations::DEFAULT_COMMANDS_PER_PAGE

Constants included from Base::TreeTracking

Base::TreeTracking::TAGTREE_BACKUP

Instance Attribute Summary

Attributes included from Lib::ErrorHandling

#exception, #exiting

Attributes included from Language::AuxiliarLogger

#logger

Attributes included from Base::TreeTracking

#current_tree, #previous_tree

Instance Method Summary collapse

Methods included from Optimizations

#commands_payload_without_structure_block, #commands_per_page, #default_tree_tracking_mode, #force_continue?, #scope_commands_block

Methods included from Base

#live_tree, #session_live_tree, #tagtree_id, #target_structure_id, #target_structure_id_const

Methods included from Language::AuxiliarLogger

#log

Methods included from Base::TreeTracking

#backup_tree, #track_current_tree, #track_current_tree?

Instance Method Details

#apply_commands(input, final: false, track_tree_mode: nil, &block) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb', line 84

def apply_commands(
  input,
  final:           false,
  track_tree_mode: nil,
  &block
)
  block ||= scope_commands_block(track_tree_mode: track_tree_mode)
  block   = nil if final

  graphql.locationStructure.draft.addCommands(input: input, &block)
end

#create_draft(structure_id, name: Time.now.iso8601, notes: '', include_archived_nodes: true) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb', line 10

def create_draft(
  structure_id,
  name:                   Time.now.iso8601,
  notes:                  '',
  include_archived_nodes: true
)
  log(:info) { "Going to create draft (for #{structure_id})..." }

  graphql.locationStructure.draft.create(
    input:                {
      structureId: structure_id,
      name:        name,
      notes:       notes
    },
    includeArchivedNodes: include_archived_nodes
  ).tap do |payload|
    unless payload.error?
      log(:info) { "Created draft '#{payload.draft&.id}' (for #{structure_id})" }
      next
    end

    msg = "Could not create draft for #{structure_id}:\n"
    msg << JSON.pretty_generate(payload.error_doc)

    raise StandardError, msg
  end
end

#delete_draft(draft_id) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb', line 38

def delete_draft(draft_id)
  graphql.locationStructure.draft.delete(
    input: {
      id: draft_id
    }
  ).tap do |payload|
    unless payload.error?
      log(:info) { "Deleted draft #{draft_id}" }
      next
    end

    msg = "Could not delete draft #{draft_id}:\n"
    msg << JSON.pretty_generate(payload.error_doc)

    raise StandardError, msg
  end
end

#publish_draft(draft_id, preview: false, force: false, include_archived_nodes: true) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb', line 56

def publish_draft(
  draft_id,
  preview:                false,
  force:                  false,
  include_archived_nodes: true
)
  log(:info) { "Going to publish draft #{draft_id}..." }

  graphql.locationStructure.draft.publish(
    input:                {
      id:      draft_id,
      preview: preview,
      force:   force
    },
    includeArchivedNodes: include_archived_nodes
  ).tap do |payload|
    unless payload.error?
      log(:info) { "Published draft #{draft_id}" }
      next
    end

    msg = "Could not publish draft #{draft_id}:\n"
    msg << JSON.pretty_generate(payload.error_doc)

    raise StandardError, msg
  end
end