docbrown/app/controllers/internal/reactions_controller.rb
Michael Kohl b06e9901d5
Add ApplicationRecord#errors_as_sentence (#8265)
* Add ApplicationRecord#errors_as_sentence

* Refactor existing uses

* Use errors as sentence more consistently
2020-06-04 16:02:41 +02:00

21 lines
680 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_as_sentence }, status: :unprocessable_entity
end
end
private
def confirmed_vomit_reaction?
@reaction.reactable_type == "User" && @reaction.status == "confirmed" && @reaction.category == "vomit"
end
end