Class: EventStoreClient::HTTP::Commands::Projections::Update

Inherits:
Command
  • Object
show all
Defined in:
lib/event_store_client/adapters/http/commands/projections/update.rb

Instance Method Summary collapse

Methods inherited from Command

inherited

Instance Method Details

#call(name, streams, options: {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/event_store_client/adapters/http/commands/projections/update.rb', line 8

def call(name, streams, options: {})
  data =
    <<~STRING
      fromStreams(#{streams})
      .when({
        $any: function(s,e) {
          linkTo("#{name}", e)
        }
      })
    STRING
  res = connection.call(
    :put,
    "/projection/#{name}/query?type=js&enabled=yes&emit=true&trackemittedstreams=true", # rubocop:disable Metrics/LineLength
    body: data,
    headers: {}
  )

  (200...300).cover?(res.status) ? Success() : Failure(res)
end