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