FIX: some reports ignored date range parameters
This commit is contained in:
parent
c618478e88
commit
32bc9a8f93
|
@ -126,9 +126,9 @@ SQL
|
|||
|
||||
def self.count_per_day_for_type(post_action_type, opts=nil)
|
||||
opts ||= {}
|
||||
opts[:since_days_ago] ||= 30
|
||||
result = unscoped.where(post_action_type_id: post_action_type)
|
||||
result = result.where('post_actions.created_at >= ?', opts[:since_days_ago].days.ago)
|
||||
result = result.where('post_actions.created_at >= ?', opts[:start_date] || (opts[:since_days_ago] || 30).days.ago)
|
||||
result = result.where('post_actions.created_at <= ?', opts[:end_date]) if opts[:end_date]
|
||||
result = result.joins(post: :topic).where('topics.category_id = ?', opts[:category_id]) if opts[:category_id]
|
||||
result.group('date(post_actions.created_at)')
|
||||
.order('date(post_actions.created_at)')
|
||||
|
|
|
@ -35,6 +35,7 @@ class Report
|
|||
|
||||
def self.find(type, opts=nil)
|
||||
opts ||= {}
|
||||
|
||||
# Load the report
|
||||
report = Report.new(type)
|
||||
report.start_date = opts[:start_date] if opts[:start_date]
|
||||
|
@ -184,7 +185,7 @@ class Report
|
|||
|
||||
def self.post_action_report(report, post_action_type)
|
||||
report.data = []
|
||||
PostAction.count_per_day_for_type(post_action_type, category_id: report.category_id).each do |date, count|
|
||||
PostAction.count_per_day_for_type(post_action_type, category_id: report.category_id, start_date: report.start_date, end_date: report.end_date).each do |date, count|
|
||||
report.data << { x: date, y: count }
|
||||
end
|
||||
countable = PostAction.unscoped.where(post_action_type_id: post_action_type)
|
||||
|
|
Loading…
Reference in New Issue