docbrown/app/controllers/internal/reactions_controller.rb
Arit Amana 9ab1979ef0
Async Vomit Confirmations & Invalidations in Internal (#7082)
* Work in Progress

* Time for Refactoring

* WIP Implementation, still lacking tests

* Incorporate PR feedback from team

* Working now

* Add specs specific to JSON being returned by "update" action

* Refactors and Bug-Fixes from PR review
2020-04-08 10:33:41 -04:00

21 lines
694 B
Ruby

class Internal::ReactionsController < Internal::ApplicationController
after_action only: [:update] do
Audit::Logger.log(:moderator, current_user, params.dup)
end
def update
@reaction = Reaction.find(params[:id])
if @reaction.update(status: params[:status])
Moderator::SinkArticles.call(@reaction.reactable_id) if confirmed_vomit_reaction?
render json: { outcome: "Success" }
else
render json: { error: @reaction.errors.full_messages.to_sentence }, status: :unprocessable_entity
end
end
private
def confirmed_vomit_reaction?
@reaction.reactable_type == "User" && @reaction.status == "confirmed" && @reaction.category == "vomit"
end
end