Skip to content

Commit

Permalink
WIP part 2
Browse files Browse the repository at this point in the history
Now I see headers for the CSV, but no data for the hours report is being rendered to the CSV.
  • Loading branch information
rae-stanton committed Aug 11, 2023
1 parent 4b07418 commit aaab2b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions app/mailers/learning_hours_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
class LearningHoursMailer < ApplicationMailer
def learning_hours_report_email(user, casa_org, csv_data)

def learning_hours_report_email(user)
@user = user
@casa_org = casa_org
attachments['learning_hours_report.csv'] = csv_data

# Ensure user is provided
if @user.nil?
Bugsnag.notify("No user provided for LearningHoursMailer#learning_hours_report_email")
return
end

@casa_org = user.casa_org

# Generate the learning hours CSV for the current month
start_date = Date.today.beginning_of_month
end_date = Date.today.end_of_month
learning_hours = LearningHour.where(user_id: @user.id, occurred_at: start_date..end_date)
csv_data = LearningHoursExportCsvService.new(learning_hours).perform

attachments["learning-hours-report-#{Date.today}.csv"] = csv_data

mail(to: @user.email, subject: "Learning Hours Report - #{last_day_of_month.strftime('%Y-%m-%d')}")
end

private

def last_day_of_month
Date.today.end_of_month
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mailers/previews/learning_hours_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def learning_hours_report_email
if user.nil?
DebugPreviewMailer.invalid_user("user")
else
LearningHoursMailer.learning_hours_report_email(user, @casa_org, @csv_data)
LearningHoursMailer.learning_hours_report_email(user)
end
end
end

0 comments on commit aaab2b0

Please sign in to comment.