-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathevent.rb
More file actions
49 lines (40 loc) · 1.52 KB
/
Copy pathevent.rb
File metadata and controls
49 lines (40 loc) · 1.52 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Event < ApplicationRecord
include Notifiable, Particulars, Promptable
belongs_to :account, default: -> { board.account }
belongs_to :board
belongs_to :creator, class_name: "User"
belongs_to :eventable, polymorphic: true
has_many :webhook_deliveries, class_name: "Webhook::Delivery", dependent: :delete_all
scope :chronologically, -> { order created_at: :asc, id: :desc }
scope :reverse_chronologically, -> { order created_at: :desc, id: :desc }
scope :for_creators, ->(ids) { where(creator_id: ids) if ids.present? }
scope :for_boards, ->(ids) { where(board_id: ids) if ids.present? }
scope :since_date, ->(date) { where("events.created_at >= ?", Date.parse(date).beginning_of_day) if date.present? }
scope :until_date, ->(date) { where("events.created_at <= ?", Date.parse(date).end_of_day) if date.present? }
scope :preloaded, -> {
includes(:creator, :board, {
eventable: [
:creator, :goldness, :closure, :image_attachment,
{ rich_text_body: :embeds_attachments },
{ rich_text_description: :embeds_attachments },
{ card: [ :goldness, :closure, :image_attachment ] }
]
})
}
after_create -> { eventable.event_was_created(self) }
after_create_commit :dispatch_webhooks
delegate :card, to: :eventable
def action
super.inquiry
end
def notifiable_target
eventable
end
def description_for(user)
Event::Description.new(self, user)
end
private
def dispatch_webhooks
Event::WebhookDispatchJob.perform_later(self)
end
end