Class: Todos::SnoozingService

Inherits:
Object
  • Object
show all
Defined in:
app/services/todos/snoozing_service.rb

Instance Method Summary collapse

Instance Method Details

#snooze_todo(todo, snooze_until) ⇒ Object



12
13
14
15
16
17
18
# File 'app/services/todos/snoozing_service.rb', line 12

def snooze_todo(todo, snooze_until)
  if todo.update(snoozed_until: snooze_until)
    ServiceResponse.success(payload: { todo: todo })
  else
    ServiceResponse.error(message: todo.errors.full_messages)
  end
end

#snooze_todos(todos, snooze_until) ⇒ Object



28
29
30
# File 'app/services/todos/snoozing_service.rb', line 28

def snooze_todos(todos, snooze_until)
  todos.batch_update(snoozed_until: snooze_until)
end

#un_snooze_todo(todo) ⇒ Object



20
21
22
23
24
25
26
# File 'app/services/todos/snoozing_service.rb', line 20

def un_snooze_todo(todo)
  if todo.snoozed_until.nil? || todo.update(snoozed_until: nil)
    ServiceResponse.success(payload: { todo: todo })
  else
    ServiceResponse.error(message: todo.errors.full_messages)
  end
end

#unsnooze_todos(todos) ⇒ Object



32
33
34
# File 'app/services/todos/snoozing_service.rb', line 32

def unsnooze_todos(todos)
  todos.batch_update(snoozed_until: nil)
end