summaryrefslogtreecommitdiff
path: root/app/models/zoom_meeting.rb
blob: c8b510c4779de5b00071ce21361e41d660755196 (plain)
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
# frozen_string_literal: true

class ZoomMeeting < ApplicationRecord
  include Importable
  include UsageStatistics

  belongs_to :project
  belongs_to :issue

  validates :project, presence: true, unless: :importing?
  validates :issue, presence: true, unless: :importing?

  validates :url, presence: true, length: { maximum: 255 }, zoom_url: true
  validates :issue, same_project_association: true, unless: :importing?

  enum issue_status: {
    added: 1,
    removed: 2
  }

  scope :added_to_issue, -> { where(issue_status: :added) }
  scope :removed_from_issue, -> { where(issue_status: :removed) }
  scope :canonical, -> (issue) { where(issue: issue).added_to_issue }

  def self.canonical_meeting(issue)
    canonical(issue)&.take
  end

  def self.canonical_meeting_url(issue)
    canonical_meeting(issue)&.url
  end
end