Skip to content

Commit

Permalink
fix: conversation bulk update
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaswinichile committed Jul 21, 2022
1 parent ef20671 commit c7a96ed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/accounts/macros_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def update
end

def execute
::MacrosExecutionJob.perform_later(@macro, conversation_id: params[:conversation_id])
::MacrosExecutionJob.perform_later(@macro, conversation_ids: params[:conversation_ids], user: current_user)

head :ok
end
Expand Down
10 changes: 7 additions & 3 deletions app/jobs/macros_execution_job.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
class MacrosExecutionJob < ApplicationJob
queue_as :medium

def perform(macro, conversation_id:)
def perform(macro, conversation_ids:, user:)
account = macro.account
conversation = account.conversations.find_by(display_id: conversation_id)
conversations = account.conversations.where(display_id: conversation_ids.to_a)

::Macros::ExecutionService.new(macro, account, conversation).perform if conversation.present?
return if conversations.blank?

conversations.each do |conversation|
::Macros::ExecutionService.new(macro, conversation, user).perform
end
end
end
6 changes: 3 additions & 3 deletions app/services/macros/execution_service.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Macros::ExecutionService
def initialize(macro, account, conversation)
def initialize(macro, conversation, user)
@macro = macro
@account = account
@account = macro.account
@conversation = conversation
Current.executed_by = macro
Current.user = user
end

def perform
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/accounts/macros_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@

perform_enqueued_jobs do
post "/api/v1/accounts/#{account.id}/macros/#{macro.id}/execute",
params: { conversation_id: conversation.display_id },
params: { conversation_ids: [conversation.display_id] },
headers: administrator.create_new_auth_token

expect(response).to have_http_status(:success)
Expand Down

0 comments on commit c7a96ed

Please sign in to comment.