Welcome to mirror list, hosted at ThFree Co, Russian Federation.

toggle.rb « award_emojis « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e741f972b1bc3a6252a69155c89f2d1b12e417a1 (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
# frozen_string_literal: true

module Mutations
  module AwardEmojis
    class Toggle < Base
      graphql_name 'AwardEmojiToggle'

      field :toggled_on, GraphQL::BOOLEAN_TYPE, null: false,
            description: 'Indicates the status of the emoji. ' \
            'True if the toggle awarded the emoji, and false if the toggle removed the emoji.'

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

        service = ::AwardEmojis::ToggleService.new(awardable, args[:name], current_user).execute

        toggled_on = awardable.awarded_emoji?(args[:name], current_user)

        {
          # For consistency with the AwardEmojis::Remove mutation, only return
          # the AwardEmoji if it was created and not destroyed
          award_emoji: (service[:award] if toggled_on),
          errors: service[:errors] || [],
          toggled_on: toggled_on
        }
      end
    end
  end
end