Guest User

Untitled

a guest
Sep 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. class Appointment < ApplicationRecord
  2.  
  3. scope :with_status, -> (status) { where(status: status) }
  4. scope :alertable, -> { where(is_alert: true) }
  5.  
  6. belongs_to :offer
  7. belongs_to :stylist
  8. belongs_to :user
  9. has_many :appointment_follow_ups
  10.  
  11. validates :user_id, presence: true
  12. validates :offer_id, presence: true
  13. validates_uniqueness_of :time, scope: [:offer_id, :date], conditions: -> { where.not(status: [APPOINTMENT_STATUS[2], APPOINTMENT_STATUS[3]]) }
  14.  
  15. before_update :refund_if_cancelled_by_s_or_a, if: -> { status_changed? and cancelled_by_admin? }
  16.  
  17. def notification_key
  18. if appointment.offer
  19. appointment.offer_id #incase offer is deleted but appointment status stays
  20. else
  21. 1
  22. end
  23. end
  24.  
  25. private
  26.  
  27. def refund_if_cancelled_by_s_or_a
  28. self.allow_refund = true
  29. end
  30.  
  31. end
Add Comment
Please, Sign In to add comment