2021-06-29 15:29:41 +00:00
|
|
|
class Api::V1::Accounts::CsatSurveyResponsesController < Api::V1::Accounts::BaseController
|
2021-07-14 14:45:57 +00:00
|
|
|
include Sift
|
2021-06-29 15:29:41 +00:00
|
|
|
include DateRangeHelper
|
|
|
|
|
|
|
|
RESULTS_PER_PAGE = 25
|
|
|
|
|
|
|
|
before_action :check_authorization
|
2021-07-14 04:50:06 +00:00
|
|
|
before_action :set_csat_survey_responses, only: [:index, :metrics]
|
|
|
|
before_action :set_current_page, only: [:index]
|
|
|
|
before_action :set_current_page_surveys, only: [:index]
|
|
|
|
before_action :set_total_sent_messages_count, only: [:metrics]
|
2021-06-29 15:29:41 +00:00
|
|
|
|
2021-07-14 14:45:57 +00:00
|
|
|
sort_on :created_at, type: :datetime
|
|
|
|
|
2021-06-29 15:29:41 +00:00
|
|
|
def index; end
|
|
|
|
|
2021-07-14 04:50:06 +00:00
|
|
|
def metrics
|
|
|
|
@total_count = @csat_survey_responses.count
|
|
|
|
@ratings_count = @csat_survey_responses.group(:rating).count
|
|
|
|
end
|
|
|
|
|
2021-06-29 15:29:41 +00:00
|
|
|
private
|
|
|
|
|
2021-07-14 04:50:06 +00:00
|
|
|
def set_total_sent_messages_count
|
|
|
|
@csat_messages = Current.account.messages.input_csat
|
|
|
|
@csat_messages = @csat_messages.where(created_at: range) if range.present?
|
|
|
|
@total_sent_messages_count = @csat_messages.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_csat_survey_responses
|
2021-07-14 14:45:57 +00:00
|
|
|
@csat_survey_responses = filtrate(
|
|
|
|
Current.account.csat_survey_responses.includes([:conversation, :assigned_agent, :contact])
|
2022-03-04 11:49:26 +00:00
|
|
|
).filter_by_created_at(range).filter_by_assigned_agent_id(params[:user_ids])
|
2021-07-14 04:50:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_current_page_surveys
|
|
|
|
@csat_survey_responses = @csat_survey_responses.page(@current_page).per(RESULTS_PER_PAGE)
|
2021-06-29 15:29:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_current_page
|
|
|
|
@current_page = params[:page] || 1
|
|
|
|
end
|
|
|
|
end
|