2019-06-21 00:45:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module AwardEmojis
|
|
|
|
class Toggle < Base
|
2020-06-23 08:09:20 -04:00
|
|
|
graphql_name 'AwardEmojiToggle'
|
2019-06-21 00:45:27 -04:00
|
|
|
|
2020-09-18 02:09:31 -04:00
|
|
|
field :toggled_on, GraphQL::BOOLEAN_TYPE, null: false,
|
2020-01-07 19:07:43 -05:00
|
|
|
description: 'Indicates the status of the emoji. ' \
|
|
|
|
'True if the toggle awarded the emoji, and false if the toggle removed the emoji.'
|
2019-06-21 00:45:27 -04:00
|
|
|
|
|
|
|
def resolve(args)
|
|
|
|
awardable = authorized_find!(id: args[:awardable_id])
|
|
|
|
|
2019-07-08 21:57:04 -04:00
|
|
|
service = ::AwardEmojis::ToggleService.new(awardable, args[:name], current_user).execute
|
2019-06-21 00:45:27 -04:00
|
|
|
|
|
|
|
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
|
2019-07-08 21:57:04 -04:00
|
|
|
award_emoji: (service[:award] if toggled_on),
|
|
|
|
errors: service[:errors] || [],
|
2019-06-21 00:45:27 -04:00
|
|
|
toggled_on: toggled_on
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|