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

module Mutations
  module AwardEmojis
    class Add < Base
      graphql_name 'AddAwardEmoji'

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

        check_object_is_awardable!(awardable)

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

        {
          award_emoji: (award if award.persisted?),
          errors: errors_on_object(award)
        }
      end
    end
  end
end