Add API support for querying admin reports by date range
This commit is contained in:
parent
fde5e739c9
commit
068d22e9b3
|
@ -13,8 +13,8 @@ class EmailLog < ActiveRecord::Base
|
|||
User.where(id: user_id).update_all("last_emailed_at = CURRENT_TIMESTAMP") if user_id.present? and !skipped
|
||||
end
|
||||
|
||||
def self.count_per_day(sinceDaysAgo = 30)
|
||||
where('created_at > ? and skipped = false', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
|
||||
def self.count_per_day(start_date, end_date)
|
||||
where('created_at >= ? and created_at < ? AND skipped = false', start_date, end_date).group('date(created_at)').order('date(created_at)').count
|
||||
end
|
||||
|
||||
def self.for(reply_key)
|
||||
|
@ -22,8 +22,7 @@ class EmailLog < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.last_sent_email_address
|
||||
where(email_type: 'signup').order('created_at DESC')
|
||||
.first.try(:to_address)
|
||||
where(email_type: 'signup').order('created_at DESC').first.try(:to_address)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -39,8 +39,8 @@ class Report
|
|||
# Load the report
|
||||
report = Report.new(type)
|
||||
|
||||
report.start_date = opts[:start_date]
|
||||
report.end_date = opts[:end_date]
|
||||
report.start_date = opts[:start_date] if opts[:start_date]
|
||||
report.end_date = opts[:end_date] if opts[:end_date]
|
||||
send(report_method, report)
|
||||
report
|
||||
end
|
||||
|
@ -70,7 +70,7 @@ class Report
|
|||
end
|
||||
|
||||
def self.report_about(report, subject_class, report_method = :count_per_day)
|
||||
basic_report_about report, subject_class, report_method, default_days
|
||||
basic_report_about report, subject_class, report_method, report.start_date, report.end_date
|
||||
add_counts(report, subject_class)
|
||||
end
|
||||
|
||||
|
|
|
@ -531,8 +531,8 @@ class User < ActiveRecord::Base
|
|||
.limit(3)
|
||||
end
|
||||
|
||||
def self.count_by_signup_date(sinceDaysAgo=30)
|
||||
where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
|
||||
def self.count_by_signup_date(start_date, end_date)
|
||||
where('created_at >= ? and created_at < ?', start_date, end_date).group('date(created_at)').order('date(created_at)').count
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ describe Admin::ReportsController do
|
|||
|
||||
context 'missing report' do
|
||||
before do
|
||||
Report.expects(:find).with('active').returns(nil)
|
||||
Report.expects(:find).with('active', instance_of(Hash)).returns(nil)
|
||||
xhr :get, :show, type: 'active'
|
||||
end
|
||||
|
||||
|
@ -42,7 +42,7 @@ describe Admin::ReportsController do
|
|||
|
||||
context 'a report is found' do
|
||||
before do
|
||||
Report.expects(:find).with('active').returns(Report.new('active'))
|
||||
Report.expects(:find).with('active', instance_of(Hash)).returns(Report.new('active'))
|
||||
xhr :get, :show, type: 'active'
|
||||
end
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ describe EmailLog do
|
|||
it "counts sent emails" do
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email)
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, skipped: true)
|
||||
described_class.count_per_day.first[1].should == 1
|
||||
described_class.count_per_day(1.day.ago, Time.now).first[1].should == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue