summaryrefslogtreecommitdiff
path: root/app/services/todos/destroy/base_service.rb
blob: aeb60e50c640f226e39837f58db352759e18307e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

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
        raise NotImplementedError
      end

      def project_ids
        raise NotImplementedError
      end

      def todos_to_remove?
        raise NotImplementedError
      end
    end
  end
end