Class: Tasker::Mutations::CancelTask

Inherits:
BaseMutation
  • Object
show all
Defined in:
app/graphql/tasker/mutations/cancel_task.rb

Instance Method Summary collapse

Instance Method Details

#resolve(task_id:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/graphql/tasker/mutations/cancel_task.rb', line 14

def resolve(task_id:)
  task = Tasker::Task.find(task_id)
  # Use state machine to transition task to cancelled
  task.state_machine.transition_to!(Tasker::Constants::TaskStatuses::CANCELLED)

  # we don't want to re-run save here because it will remove the
  # context validation from the handler and check "valid?"
  if task.errors.empty?
    Tasker::TaskSerializer.new(task).to_hash
  else
    { task: nil, errors: task.errors }
  end
end