2018-08-11 03:00:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-16 14:30:17 -04:00
|
|
|
module Todos
|
|
|
|
module Destroy
|
|
|
|
class BaseService
|
|
|
|
def execute
|
|
|
|
return unless todos_to_remove?
|
|
|
|
|
|
|
|
without_authorized(todos).delete_all
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def without_authorized(items)
|
|
|
|
items.where('user_id NOT IN (?)', authorized_users)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorized_users
|
|
|
|
ProjectAuthorization.select(:user_id).where(project_id: project_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def todos
|
2018-07-27 05:28:17 -04:00
|
|
|
raise NotImplementedError
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_ids
|
2018-07-27 05:28:17 -04:00
|
|
|
raise NotImplementedError
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def todos_to_remove?
|
2018-07-27 05:28:17 -04:00
|
|
|
raise NotImplementedError
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|