Class: Mutations::AwardEmojis::Toggle

Inherits:
Base
  • Object
show all
Defined in:
app/graphql/mutations/award_emojis/toggle.rb

Constant Summary

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, #current_user, #errors_on_object, #ready?

Instance Method Details

#resolve(args) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/graphql/mutations/award_emojis/toggle.rb', line 12

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

  check_object_is_awardable!(awardable)

  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