debian-mirror-gitlab/app/services/work_items/delete_task_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.3 KiB
Ruby
Raw Normal View History

2022-07-16 23:28:13 +05:30
# frozen_string_literal: true
module WorkItems
class DeleteTaskService
2023-03-04 22:38:38 +05:30
def initialize(work_item:, lock_version:, current_user: nil, task_params: {})
2022-07-16 23:28:13 +05:30
@work_item = work_item
@current_user = current_user
@task_params = task_params
@lock_version = lock_version
@task = task_params[:task]
@errors = []
end
def execute
transaction_result = ::WorkItem.transaction do
replacement_result = TaskListReferenceRemovalService.new(
work_item: @work_item,
task: @task,
line_number_start: @task_params[:line_number_start],
line_number_end: @task_params[:line_number_end],
lock_version: @lock_version,
current_user: @current_user
).execute
break ::ServiceResponse.error(message: replacement_result.errors, http_status: 422) if replacement_result.error?
delete_result = ::WorkItems::DeleteService.new(
project: @task.project,
current_user: @current_user
).execute(@task)
if delete_result.error?
@errors += delete_result.errors
raise ActiveRecord::Rollback
end
delete_result
end
return transaction_result if transaction_result
::ServiceResponse.error(message: @errors, http_status: 422)
end
end
end