Sha256: c3eab4ff89c5f612fc63a15f1449df34b660b1d439b83bab9ce5624bc2c8d665
Contents?: true
Size: 1.29 KB
Versions: 9
Compression:
Stored size: 1.29 KB
Contents
require_dependency "renalware/letters" # Represents an Electronic CC - a reference to a letter sent to a recipient (another user on the # system) as a 'CC'. We use the concept of a 'receipt' which, while mainly being a cross table # between letter and recipient user, is also a well-named place to store related information # for example whether the message has been read (e.g. the letter viewed). module Renalware module Letters class ElectronicReceipt < ApplicationRecord belongs_to :letter, touch: true belongs_to :recipient, class_name: "Renalware::User" validates :letter, presence: true validates :recipient_id, presence: true # Merge scope here to make sure we only get approved letters scope :sent_by, lambda{ |user_id| joins(:letter) .merge(Letter::Approved.all) .where(letter_letters: { author_id: user_id }) } scope :unread, -> { where(read_at: nil).joins(:letter).merge(Letter::Approved.all) } scope :read, -> { where.not(read_at: nil).joins(:letter).merge(Letter::Approved.all) } scope :for_recipient, ->(user_id) { where(recipient_id: user_id) } scope :ordered, -> { order(created_at: :desc) } def read? read_at.present? end def unread? !read? end end end end
Version data entries
9 entries across 9 versions & 1 rubygems