Class: TmsTaskManager::Services::Task

Inherits:
Object
  • Object
show all
Extended by:
Helpers::ErrorHandler
Defined in:
lib/tms_task_manager/services/task.rb

Class Method Summary collapse

Methods included from Helpers::ErrorHandler

handle_errors

Class Method Details

.update_status(id, status) ⇒ Object

Updates the status of a task



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tms_task_manager/services/task.rb', line 13

def self.update_status(id, status)
  handle_errors do
    raise 'Status must be "pending", "in_progress" or "completed"' unless %w[pending in_progress completed].include?(status.downcase)

    task = @db.execute('SELECT * FROM tasks WHERE id = ?', [id]).first
    if task.nil?
      puts "Task not found: #{id}"
      return { success: false, message: 'Task not found' }
    end

    @db.execute('UPDATE tasks SET status = ? WHERE id = ?', [status, id])
    updated_task = task.merge('status' => status)
    puts "Task updated successfully: ID: #{id}, New Status: #{status}"
    { success: true, message: "Task updated: #{id}", task: updated_task }
  end
end