RailsEventStore/cqrs-es-sample-with-res

View on GitHub
rails_application/app/read_models/customers/connect_account.rb

Summary

Maintainability
A
20 mins
Test Coverage
module Customers
  class ConnectAccount < Infra::EventHandler
    def call(event)
      ApplicationRecord.with_advisory_lock(event.data.fetch(:client_id)) do
        Customer.find_or_create_by(id: event.data.fetch(:client_id)).update(account_id: event.data.fetch(:account_id))
      end
    end
  end
end