Skip to content

Commit

Permalink
in the event of no modulerelease records, populate with training modu…
Browse files Browse the repository at this point in the history
…le data
  • Loading branch information
jack-coggin committed Aug 23, 2023
1 parent 68d4091 commit 3d7a2b6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/jobs/new_module_mail_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ def notify_users(mod)
User.completed_available_modules.each { |recipient| NotifyMailer.new_module(recipient, mod) }
end

# @return [void]
def populate_module_releases
Training::Module.ordered.reject(&:draft?).each do |mod|
ModuleRelease.create!(release_id: Release.last.id, module_position: mod.position, name: mod.name, first_published_at: Release.last.time)
end
end

# @return [Training::Module, nil]
def new_module
populate_module_releases if ModuleRelease.count.zero?
latest_published = Training::Module.ordered.reject(&:draft?).last
if latest_published.position == ModuleRelease.ordered.last.module_position
nil
Expand Down

0 comments on commit 3d7a2b6

Please sign in to comment.