Sha256: 8c7dd2462f04136af39fd57f36e97d2ae71ae10507c591b1187d38567f564c9b
Contents?: true
Size: 1.42 KB
Versions: 87
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true 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, lambda { where(read_at: nil) .joins(:letter) .merge(Letter.approved_or_completed) } scope :read, lambda { where.not(read_at: nil) .joins(:letter) .merge(Letter.approved_or_completed) } 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
87 entries across 87 versions & 1 rubygems