2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module AwardEmojis
|
|
|
|
class Toggle < Base
|
2020-07-28 23:09:34 +05:30
|
|
|
graphql_name 'AwardEmojiToggle'
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
field :toggled_on, GraphQL::Types::Boolean, null: false,
|
2020-03-13 15:44:24 +05:30
|
|
|
description: 'Indicates the status of the emoji. ' \
|
|
|
|
'True if the toggle awarded the emoji, and false if the toggle removed the emoji.'
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
def resolve(args)
|
|
|
|
awardable = authorized_find!(id: args[:awardable_id])
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
service = ::AwardEmojis::ToggleService.new(awardable, args[:name], current_user).execute
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
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-12-04 20:38:33 +05:30
|
|
|
award_emoji: (service[:award] if toggled_on),
|
|
|
|
errors: service[:errors] || [],
|
2019-09-30 21:07:59 +05:30
|
|
|
toggled_on: toggled_on
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|