Skip to content

Commit

Permalink
Slightly refactor store_events
Browse files Browse the repository at this point in the history
  • Loading branch information
erikrozendaal committed Feb 8, 2024
1 parent 6beb1e8 commit 02e7c55
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/sequent/core/event_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ def publish_events(events)

def store_events(command, streams_with_events = [])
command_record = CommandRecord.create!(command: command)
json = streams_with_events.map do |event_stream, uncommitted_events|
stream = Oj.strict_load(Oj.dump(event_stream))
json = streams_with_events.map do |stream, uncommitted_events|
[
stream,
Oj.strict_load(Oj.dump(stream)),
uncommitted_events.map do |event|
r = Sequent::Core::Oj.strict_load(Sequent::Core::Oj.dump(event))
# Since ActiveRecord uses `TIMESTAMP WITHOUT TIME ZONE`
# we need to manually convert database timestamps to the
# ActiveRecord default time zone on serialization.
r['created_at'] = ActiveRecord.default_timezone == :utc ? event.created_at.to_time.getutc : event.created_at.to_time.getlocal
created_at = event.created_at.to_time
r['created_at'] = ActiveRecord.default_timezone == :utc ? created_at.getutc : created_at.getlocal
r['event_type'] = event.class.name
r
end,
Expand Down

0 comments on commit 02e7c55

Please sign in to comment.