Class: AgendrixTimeEntryResolver

Inherits:
Object
  • Object
show all
Defined in:
app/resolver/agendrix_time_entry_resolver.rb

Defined Under Namespace

Classes: Actions

Constant Summary collapse

USER_NAME =
'SYSTEM'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(company_id:, employee_id:, employee_role_id:, time_entry:) ⇒ AgendrixTimeEntryResolver

Returns a new instance of AgendrixTimeEntryResolver.



14
15
16
17
18
19
20
21
22
23
24
# File 'app/resolver/agendrix_time_entry_resolver.rb', line 14

def initialize(
  company_id:,
  employee_id:,
  employee_role_id:,
  time_entry:
)
  @company_id = company_id
  @employee_id = employee_id
  @employee_role_id = employee_role_id
  @time_entry = time_entry
end

Instance Attribute Details

#company_idObject (readonly)

Returns the value of attribute company_id.



12
13
14
# File 'app/resolver/agendrix_time_entry_resolver.rb', line 12

def company_id
  @company_id
end

#employee_idObject (readonly)

Returns the value of attribute employee_id.



12
13
14
# File 'app/resolver/agendrix_time_entry_resolver.rb', line 12

def employee_id
  @employee_id
end

#employee_role_idObject (readonly)

Returns the value of attribute employee_role_id.



12
13
14
# File 'app/resolver/agendrix_time_entry_resolver.rb', line 12

def employee_role_id
  @employee_role_id
end

#time_entryObject (readonly)

Returns the value of attribute time_entry.



12
13
14
# File 'app/resolver/agendrix_time_entry_resolver.rb', line 12

def time_entry
  @time_entry
end

Instance Method Details

#resolveObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/resolver/agendrix_time_entry_resolver.rb', line 26

def resolve
  ActiveRecord::Base.transaction do
    if find_integrated_timesheet
      update_timesheet

      { action: Actions::UPDATE, timesheet: @employee_timesheet, time_entry: time_entry }
    elsif find_timesheet_to_integrate
      integrate_timesheet
      update_timesheet

      { action: Actions::INTEGRATE, timesheet: @employee_timesheet, time_entry: time_entry }
    elsif create_timesheet
      integrate_timesheet

      { action: Actions::CREATE, timesheet: @employee_timesheet, time_entry: time_entry }
    end
  end
rescue StandardError => e
  Rails.logger.error "Failed to resolve Agendrix time_entry: #{e.message}, time_entry: #{time_entry}"
  raise e
end