-
-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathorganization_status.rb
More file actions
60 lines (52 loc) · 1.7 KB
/
Copy pathorganization_status.rb
File metadata and controls
60 lines (52 loc) · 1.7 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
50
51
52
53
54
55
56
57
58
59
60
# == Schema Information
#
# Table name: organization_statuses
#
# id :bigint not null, primary key
# end_at :datetime
# kind :integer
# organization_deleted_at :datetime
# pos_kind :integer
# start_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# organization_id :bigint
#
# Indexes
#
# index_organization_statuses_on_organization_id (organization_id)
#
class OrganizationStatus < AnalyticsRecord
belongs_to :organization
enum :pos_kind, Organization::POS_KIND_ENUM
enum :kind, Organization::KIND_ENUM
has_one :notification, as: :notifiable
scope :not_deleted, -> { where(organization_deleted_at: nil) }
scope :deleted, -> { where.not(organization_deleted_at: nil) }
scope :current, -> { where(end_at: nil) }
scope :ended, -> { where.not(end_at: nil) }
scope :broken_pos, -> { where(pos_kind: Organization.broken_pos_kinds) }
scope :with_pos, -> { where(pos_kind: Organization.with_pos_kinds) }
scope :without_pos, -> { where(pos_kind: Organization.without_pos_kinds) }
def self.at_time(time)
where("start_at < ?", time).where("end_at > ?", time)
.or(current.where("start_at < ?", time))
end
def bulk_imports
if Organization.ascend_or_broken_ascend_kinds.include?(pos_kind)
b_imports = BulkImport.where("created_at > ?", start_at)
ended? ? b_imports.where("created_at < ?", end_at) : b_imports
else
BulkImport.none
end
end
def ended?
end_at.present?
end
def deleted?
organization_deleted_at.present?
end
def current?
!ended? && !deleted?
end
end