Skip to content

Instantly share code, notes, and snippets.

@bearded-avenger
Created September 10, 2020 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bearded-avenger/0ecdcadbf2915f9c749af37ea63328d2 to your computer and use it in GitHub Desktop.
Save bearded-avenger/0ecdcadbf2915f9c749af37ea63328d2 to your computer and use it in GitHub Desktop.
class CustomerNotification < ApplicationRecord
belongs_to :site
belongs_to :customer
belongs_to :notifyable, polymorphic: true
acts_as_tenant :site
validates_uniqueness_to_tenant :customer_id, scope: [:notifyable_id, :notifyable_type]
end
class TenantNotifyPlaylistFollowersJob < ApplicationJob
queue_as :default
def perform(playlist_item_id)
@playlist_item = PlaylistItem.find_by_id(playlist_item_id)
return unless @playlist_item.present?
@playlist = @playlist_item.playlist
return unless @playlist.present?
return unless @playlist.playlist_followers.exists?
@playlist.playlist_followers.find_each do |playlist_follower|
@playlist_item.customer_notifications.create!(site: @playlist.site, customer: playlist_follower.customer)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment