Class: Employees::CreateService

Inherits:
Object
  • Object
show all
Defined in:
app/services/employees/create_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(employee_params:, erp_user_params:, current_user:, current_company:) ⇒ CreateService

Returns a new instance of CreateService.



8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/employees/create_service.rb', line 8

def initialize(
  employee_params:,
  erp_user_params:,
  current_user:,
  current_company:
)
  @employee_params  = employee_params
  @erp_user_params  = erp_user_params
  @current_user     = current_user
  @current_company  = current_company
end

Instance Attribute Details

#current_companyObject (readonly)

Returns the value of attribute current_company.



3
4
5
# File 'app/services/employees/create_service.rb', line 3

def current_company
  @current_company
end

#current_userObject (readonly)

Returns the value of attribute current_user.



3
4
5
# File 'app/services/employees/create_service.rb', line 3

def current_user
  @current_user
end

#employee_paramsObject (readonly)

Returns the value of attribute employee_params.



3
4
5
# File 'app/services/employees/create_service.rb', line 3

def employee_params
  @employee_params
end

#erp_user_paramsObject (readonly)

Returns the value of attribute erp_user_params.



3
4
5
# File 'app/services/employees/create_service.rb', line 3

def erp_user_params
  @erp_user_params
end

Instance Method Details

#build_employeeObject



32
33
34
35
36
# File 'app/services/employees/create_service.rb', line 32

def build_employee
  @employee = Employee.new
  @employee.assign_attributes(employee_params.except(:employee_id))
  @employee
end

#callObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/employees/create_service.rb', line 20

def call
  ActiveRecord::Base.transaction do
    create_record
    find_and_update_or_create_erp_user
    associate_user
    validate_after_associations
    send_invitation_email

    @employee
  end
end