Class: Testimonials::Api::StatsController

Inherits:
BaseController show all
Defined in:
app/controllers/testimonials/api/stats_controller.rb

Overview

Powers rating badges: "★ 4.9 from 87 reviews".

Instance Method Summary collapse

Instance Method Details

#showObject



7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/testimonials/api/stats_controller.rb', line 7

def show
  scope = Testimonial.publishable
  rated = scope.where.not(rating: nil)

  render json: {
    count: scope.count,
    average_rating: rated.average(:rating)&.to_f&.round(2),
    ratings_count: rated.count,
    nps_score: (NpsResponse.score if Testimonials.config.nps)
  }
end