2016-11-19 16:34:48 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
module Admin
|
|
|
|
class VoteController < AdminController
|
|
|
|
def up
|
|
|
|
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
2016-11-20 13:07:53 -06:00
|
|
|
authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id)
|
2016-11-19 16:34:48 -06:00
|
|
|
current_user.cast_yea_on(@candidate)
|
|
|
|
|
|
|
|
results = {
|
2016-11-20 11:24:17 -06:00
|
|
|
message: "Vote Counted",
|
2016-11-19 16:34:48 -06:00
|
|
|
upCount: @candidate.votes.yea.count,
|
2016-11-20 11:24:17 -06:00
|
|
|
downCount: @candidate.votes.nay.count,
|
|
|
|
myVote: "yea"
|
2016-11-19 16:34:48 -06:00
|
|
|
}
|
|
|
|
render json: results.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
2016-11-20 13:07:53 -06:00
|
|
|
authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id)
|
2016-11-19 16:34:48 -06:00
|
|
|
current_user.cast_nay_on(@candidate)
|
|
|
|
|
|
|
|
results = {
|
2016-11-20 11:24:17 -06:00
|
|
|
message: "Vote Counted",
|
2016-11-19 16:34:48 -06:00
|
|
|
upCount: @candidate.votes.yea.count,
|
2016-11-20 11:24:17 -06:00
|
|
|
downCount: @candidate.votes.nay.count,
|
|
|
|
myVote: "nay"
|
2016-11-19 16:34:48 -06:00
|
|
|
}
|
|
|
|
render json: results.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def approve
|
|
|
|
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
2016-11-20 13:07:53 -06:00
|
|
|
authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id)
|
2016-11-19 16:34:48 -06:00
|
|
|
|
2016-11-30 18:55:27 -06:00
|
|
|
if current_user.approve_candidate(@candidate)
|
|
|
|
RecruiterMailer.interview_requested(@candidate).deliver_later
|
|
|
|
results = {
|
|
|
|
message: "Interview requested!",
|
|
|
|
requestCopy: "Requested",
|
|
|
|
declineCopy: "Decline Interview"
|
|
|
|
}
|
|
|
|
render json: results.to_json
|
|
|
|
end
|
2016-11-19 16:34:48 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def decline
|
|
|
|
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
2016-11-20 13:07:53 -06:00
|
|
|
authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id)
|
2016-11-19 16:34:48 -06:00
|
|
|
|
2016-11-30 18:55:27 -06:00
|
|
|
if current_user.decline_candidate(@candidate)
|
|
|
|
RecruiterMailer.interview_declined(@candidate).deliver_later
|
|
|
|
results = {
|
|
|
|
message: "Interview declined.",
|
|
|
|
requestCopy: "Request Interview",
|
|
|
|
declineCopy: "Declined"
|
|
|
|
}
|
|
|
|
render json: results.to_json
|
|
|
|
end
|
2016-11-19 16:34:48 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|