summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/award_emojis/remove.rb
blob: 3ba85e445b811c467b0b4d955e3d0414c8857b19 (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
# frozen_string_literal: true

module Mutations
  module AwardEmojis
    class Remove < Base
      graphql_name 'RemoveAwardEmoji'

      def resolve(args)
        awardable = authorized_find!(id: args[:awardable_id])

        check_object_is_awardable!(awardable)

        # TODO this check can be removed once AwardEmoji services are available.
        # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
        # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
        unless awardable.awarded_emoji?(args[:name], current_user)
          raise Gitlab::Graphql::Errors::ResourceNotAvailable,
                'You have not awarded emoji of type name to the awardable'
        end

        # TODO this will be handled by AwardEmoji::DestroyService
        # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
        # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
        awardable.remove_award_emoji(args[:name], current_user)

        {
          # Mutation response is always a `nil` award_emoji
          errors: []
        }
      end
    end
  end
end