Skip to content

Commit

Permalink
leaderboard reports scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
pjurewicz committed Oct 10, 2023
1 parent 83fbac3 commit 58885d3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/daily_leaderboard.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class DailyLeaderboard < ActiveRecord::Base
self.table_name = 'daily_leaderboard'
scope :by_period, -> (starting_date, duration) { where('date >= ? and date < ?', starting_date, starting_date + duration) }
scope :for_this_week, -> (time_zone) { by_period(Time.now.in_time_zone(time_zone).beginning_of_week.to_date, 7.days) }
scope :for_this_month, -> (time_zone) { by_period(Time.now.in_time_zone(time_zone).beginning_of_month.to_date, 1.month) }
scope :top, -> (limit = 10) { order(points: :desc).limit(limit) }

def self.rebuild_read_model!(event_store = Rails.configuration.event_store)
DailyLeaderboard.delete_all
Expand Down

0 comments on commit 58885d3

Please sign in to comment.