Class: StaffService::TemporaryAccess

Inherits:
ApplicationService
  • Object
show all
Includes:
DefaultErrorContainer
Defined in:
app/services/staff_service/temporary_access.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DefaultErrorContainer

#error, #error_message_simple, #merge_errors

Constructor Details

#initialize(restaurant_ids, account = nil) ⇒ TemporaryAccess

Returns a new instance of TemporaryAccess.



5
6
7
8
# File 'app/services/staff_service/temporary_access.rb', line 5

def initialize(restaurant_ids,  = nil)
  @restaurant_ids = Array(restaurant_ids) # Ensure it's always an array
  @account = 
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



3
4
5
# File 'app/services/staff_service/temporary_access.rb', line 3

def 
  @account
end

#expired_atObject (readonly)

Returns the value of attribute expired_at.



3
4
5
# File 'app/services/staff_service/temporary_access.rb', line 3

def expired_at
  @expired_at
end

#passwordObject (readonly)

Returns the value of attribute password.



3
4
5
# File 'app/services/staff_service/temporary_access.rb', line 3

def password
  @password
end

#restaurant_idsObject (readonly)

Returns the value of attribute restaurant_ids.



3
4
5
# File 'app/services/staff_service/temporary_access.rb', line 3

def restaurant_ids
  @restaurant_ids
end

#staffObject (readonly)

Returns the value of attribute staff.



3
4
5
# File 'app/services/staff_service/temporary_access.rb', line 3

def staff
  @staff
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
# File 'app/services/staff_service/temporary_access.rb', line 10

def call
  return false unless valid?

  create_temporary_staff
  create_staff_roles
  send_credentials_email
  schedule_deletion
end

#resultObject



19
20
21
# File 'app/services/staff_service/temporary_access.rb', line 19

def result
  { email: staff.email, password: password, expired_at: expired_at, auto_login_url:  }
end

#success?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/services/staff_service/temporary_access.rb', line 23

def success?
  errors.blank?
end