-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathtopic.rb
29 lines (22 loc) · 905 Bytes
/
topic.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true
class Topic < ApplicationRecord
include Slug
extend ApiHandling
expose_api :id, :event_id, :user_id, :name, :description, :user
PROPOSAL_TYPES = %w[proposal enquiry].freeze
validates :user, :name, :description, :label, presence: true
validates :proposal_type, inclusion: { in: PROPOSAL_TYPES }
validates :name, length: { maximum: 255 }
belongs_to :user
belongs_to :event, optional: true
has_many :likes, dependent: :destroy
has_many :materials
scope :ordered, -> { order('created_at DESC') }
scope :undone, -> { where('event_id IS NULL') }
scope :done, -> { joins(:event).where('date <= ?', Time.now - 2.hours) }
scope :upcoming, -> { joins(:event).where('date > ?', Time.now - 2.hours) }
default_scope -> { where(label: Whitelabel[:label_id]) }
def already_liked?(user)
likes.detect { |like| like.user == user }
end
end