Skip to content

Commit

Permalink
attach session details inside account
Browse files Browse the repository at this point in the history
  • Loading branch information
raghuramg committed Dec 29, 2023
1 parent fdbd248 commit 817b07e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/event_source/operations/build_message_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BuildMessageOptions
def call(params)
headers = yield build_headers(params)
payload = yield build_payload(params)
headers = yield append_session_details(headers)
headers = yield append_account_details(headers)

Success(headers: headers, payload: payload)
end
Expand All @@ -36,17 +36,20 @@ def build_payload(params)
Success(payload)
end

def append_session_details(headers)
def append_account_details(headers)
output = FetchSession.new.call
account = {}

if output.success?
session, current_user = output.value!
headers[:session] = session&.symbolize_keys
account[:session] = session&.symbolize_keys
else
# Create system account user <[email protected]> when session is not available
current_user = system_account if defined?(system_account)
end
headers[:account_id] = current_user&.id&.to_s

account[:id] = current_user&.id&.to_s
headers[:account] = account

Success(headers)
end
Expand Down

0 comments on commit 817b07e

Please sign in to comment.