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, #create_payload_without_structure_block, #force_continue?, #publish_payload_without_structure_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

#add_commands(input, &block) ⇒ Object



94
95
96
97
98
99
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb', line 94

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

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb', line 24

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

  graphql.locationStructure.draft.create(
    input: {
      structureId: structure_id,
      name:        name,
      notes:       notes
    }
  ).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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb', line 50

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

#fetch_draft(draft_id, structure_id:, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb', line 10

def fetch_draft(
  draft_id,
  structure_id:,
  &block
)
  log(:info) { "Going to fetch draft #{draft_id} (for #{structure_id})..." }

  graphql.currentOrganization.locationDraftById(
    id:          draft_id,
    structureId: structure_id,
    &block
  )
end

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



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
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb', line 68

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

  graphql.locationStructure.draft.publish(
    input: {
      id:      draft_id,
      preview: preview,
      force:   force
    }
  ).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