saucy/app/models/notification.rb

20 lines
482 B
Ruby
Raw Normal View History

2022-06-25 12:48:46 +00:00
class Notification < ApplicationRecord
belongs_to :member
scope :scheduled_for_today, ->() { where(status: 'scheduled', to_be_sent_on: Date.today) }
def self.send_scheduled_for_today
scheduled_for_today.each do |n|
n.deliver!
end
end
def deliver!
# actually send the email.
NotificationMailer.with(notification: self).send(template).deliver_now!
update(status: 'sent', sent_at: Time.current)
# TODO: do something about failures
end
end