self.update_task

in src/task.rb [101:123]


  def self.update_task(task_id:, title: nil, description: nil, status: nil)
    item = find(task_id: task_id, table_name: "TASK")
    if item
      now = Time.now
      item.title = title unless title.nil?
      item.description = description unless description.nil?
      item.status = status unless status.nil?
      item.updated_at = now
      if item.save
        [item, nil]
      else
        if item.valid? 
          puts "[ERROR] Unknown issue trying to update valid item #{item.to_h} on app table."
          [nil, ServerError.new]
        else 
          [nil, InvalidInputException.new(item.errors.full_messages.join(", "))]
        end
      end
    else
      [nil, TaskNotFoundException.new(task_id)]
    end
  end