2019-06-17 21:44:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module AwardEmojis
|
|
|
|
class DestroyService < AwardEmojis::BaseService
|
|
|
|
def execute
|
|
|
|
unless awardable.user_can_award?(current_user)
|
|
|
|
return error('User cannot destroy emoji on the awardable', status: :forbidden)
|
|
|
|
end
|
|
|
|
|
|
|
|
awards = AwardEmojisFinder.new(awardable, name: name, awarded_by: current_user).execute
|
|
|
|
|
|
|
|
if awards.empty?
|
|
|
|
return error("User has not awarded emoji of type #{name} on the awardable", status: :forbidden)
|
|
|
|
end
|
|
|
|
|
2020-05-28 17:08:22 -04:00
|
|
|
award = awards.destroy_all.first # rubocop: disable Cop/DestroyAll
|
2020-03-31 14:07:42 -04:00
|
|
|
after_destroy(award)
|
2019-06-17 21:44:43 -04:00
|
|
|
|
|
|
|
success(award: award)
|
|
|
|
end
|
2020-03-31 14:07:42 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def after_destroy(award)
|
|
|
|
end
|
2019-06-17 21:44:43 -04:00
|
|
|
end
|
|
|
|
end
|
2020-03-31 14:07:42 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
AwardEmojis::DestroyService.prepend_mod_with('AwardEmojis::DestroyService')
|