-
-
Notifications
You must be signed in to change notification settings - Fork 573
Expand file tree
/
Copy pathrequest_approval_service.rb
More file actions
42 lines (32 loc) · 1.03 KB
/
request_approval_service.rb
File metadata and controls
42 lines (32 loc) · 1.03 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
module Partners
class RequestApprovalService
include ServiceObjectErrorsMixin
# Creates a new instance of Partners::RequestApprovalService
#
# @param partner: [Partner] the partner record
#
# @return [Partners::RequestApprovalService]
def initialize(partner:)
@partner = partner
end
def call
return self unless valid?
partner.awaiting_review!
OrganizationMailer.partner_approval_request(organization: partner.organization, partner: partner).deliver_later
self
end
private
attr_reader :partner
def valid?
if partner.status == 'awaiting_review'
errors.add(:base, 'This partner has already requested approval.')
end
unless partner.profile.valid?(:edit)
errors.add :base, partner.profile.errors.full_messages.join('. ')
end
errors.merge! partner.profile.errors if partner.profile.check_social_media
errors.merge! partner.profile.errors if partner.profile.check_mandatory_fields
errors.none?
end
end
end