2016-04-16 15:09:08 -04:00
|
|
|
module ToggleAwardEmoji
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
before_action :authenticate_user!, only: [:toggle_award_emoji]
|
|
|
|
end
|
|
|
|
|
|
|
|
def toggle_award_emoji
|
|
|
|
name = params.require(:name)
|
2016-05-17 13:28:17 -04:00
|
|
|
|
2016-08-30 15:57:47 -04:00
|
|
|
if awardable.user_can_award?(current_user, name)
|
|
|
|
awardable.toggle_award_emoji(name, current_user)
|
|
|
|
TodoService.new.new_award_emoji(to_todoable(awardable), current_user)
|
2016-08-17 07:21:06 -04:00
|
|
|
|
2016-08-30 15:57:47 -04:00
|
|
|
render json: { ok: true }
|
|
|
|
else
|
|
|
|
render json: { ok: false }
|
|
|
|
end
|
2016-04-16 15:09:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-05-25 15:07:36 -04:00
|
|
|
def to_todoable(awardable)
|
|
|
|
case awardable
|
|
|
|
when Note
|
|
|
|
awardable.noteable
|
|
|
|
else
|
|
|
|
awardable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-16 15:09:08 -04:00
|
|
|
def awardable
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|