Class: Tasker::Mutations::UpdateTask

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

Constant Summary collapse

ALLOWED_UPDATE_FIELDS =
%i[reason tags].freeze

Instance Method Summary collapse

Instance Method Details

#resolve(task_id:, **args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/graphql/tasker/mutations/update_task.rb', line 17

def resolve(task_id:, **args)
  task = Tasker::Task.find(task_id)
  params = {}
  args.each do |key, val|
    params[key] = val if key.to_sym.in?(ALLOWED_UPDATE_FIELDS)
  end
  task.update!(params) unless params.empty?

  # 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