generated from BCDevOps/opendev-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcontractor_import.rb
More file actions
38 lines (32 loc) · 907 Bytes
/
contractor_import.rb
File metadata and controls
38 lines (32 loc) · 907 Bytes
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
class ContractorImport < ApplicationRecord
scope :email_not_sent, -> { where(invite_email_sent_at: nil) }
scope :email_sent, -> { where.not(invite_email_sent_at: nil) }
def invite_email_sent?
invite_email_sent_at.present?
end
def invite!
raise "Invite already sent" if invite_email_sent?
raise "Invite already consumed" if consumed?
self.class.transaction do
PermitHubMailer.contractor_invite(self)&.deliver_later
update!(invite_email_sent_at: Time.current)
end
end
def summary
{
invite_code: invite_code,
business_name: payload.dig("business", "name"),
primary_contact: payload.dig("contacts", "primary")
}
end
def consumed?
consumed_at.present?
end
def consume!(user:, contractor:)
update!(
consumed_at: Time.current,
consumed_by_user_id: user.id,
contractor_id: contractor.id
)
end
end