Class: PartnerService::Staff::CreateFromOwner
- Inherits:
-
Object
- Object
- PartnerService::Staff::CreateFromOwner
- Includes:
- DefaultErrorContainer
- Defined in:
- app/services/partner_service/staff/create_from_owner.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#result ⇒ Staff
Returns the existing staff if found by email.
Instance Method Summary collapse
-
#call ⇒ self
Main entry point for the service.
-
#data ⇒ Staff?
Retrieves the resulting data, which could be the newly created staff or the existing one.
-
#error_message ⇒ String
Retrieves a simplified error message if any error occurred during the operation.
-
#initialize(account) ⇒ CreateFromOwner
constructor
Initializes the service with an account and checks if the staff already exists.
-
#success? ⇒ Boolean
Checks if the operation was successful.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Constructor Details
#initialize(account) ⇒ CreateFromOwner
Initializes the service with an account and checks if the staff already exists.
16 17 18 19 20 21 |
# File 'app/services/partner_service/staff/create_from_owner.rb', line 16 def initialize(account) @account = account @existing_staff = Staff.find_by(email: account.email) @result = { success: false, data: nil } @password = nil end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
12 13 14 |
# File 'app/services/partner_service/staff/create_from_owner.rb', line 12 def password @password end |
#result ⇒ Staff
Returns the existing staff if found by email.
12 13 14 |
# File 'app/services/partner_service/staff/create_from_owner.rb', line 12 def result @result end |
Instance Method Details
#call ⇒ self
Main entry point for the service. Executes the logic to either handle an existing staff member or create a new one. Uses transactions to ensure atomicity in case of errors.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/partner_service/staff/create_from_owner.rb', line 28 def call return handle_existing_staff if existing_staff.present? ActiveRecord::Base.transaction do build_new_staff assign_roles save_new_staff update_partner_portal_usage_and_sync rescue StandardError => e error.add(:base, e.) @result[:success] = false end self end |
#data ⇒ Staff?
Retrieves the resulting data, which could be the newly created staff or the existing one.
52 53 54 |
# File 'app/services/partner_service/staff/create_from_owner.rb', line 52 def data @result[:data] end |
#error_message ⇒ String
Retrieves a simplified error message if any error occurred during the operation.
58 59 60 |
# File 'app/services/partner_service/staff/create_from_owner.rb', line 58 def end |
#success? ⇒ Boolean
Checks if the operation was successful.
46 47 48 |
# File 'app/services/partner_service/staff/create_from_owner.rb', line 46 def success? @result[:success] end |