Class: BunnyApp::Tenant

Inherits:
Object
  • Object
show all
Defined in:
lib/bunny_app/tenant.rb

Class Method Summary collapse

Class Method Details

.create(name:, code:, account_id:, platform_code: 'main') ⇒ Object

Raises:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/bunny_app/tenant.rb', line 60

def self.create(name:, code:, account_id:, platform_code: 'main')
  variables = {
    attributes: {
      name:,
      code:,
      platformCode: platform_code,
      accountId: 
    }
  }

  res = Client.new.query(@tenant_create_mutation, variables)
  raise ResponseError, res['data']['tenantCreate']['errors'].join(',') if res['data']['tenantCreate']['errors']

  res['data']['tenantCreate']['tenant']
end

.find_by(code:) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/bunny_app/tenant.rb', line 99

def self.find_by(code:)
  variables = { code: }

  res = Client.new.query(@tenant_query, variables)

  res['data']['tenant']
end

.update(id: nil, code: nil, **attrs) ⇒ Object

Raises:

  • (ArgumentError)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bunny_app/tenant.rb', line 76

def self.update(id: nil, code: nil, **attrs)
  raise ArgumentError, 'id or code is required' unless id || code

  # When id is the lookup key, code is treated as an attribute to update.
  # When only code is provided, it is the lookup key.
  lookup_code = id ? nil : code
  update_code = id ? code : attrs[:code]

  attributes = {
    name: attrs[:name],
    code: update_code,
    subdomain: attrs[:subdomain],
    lastLogin: attrs[:last_login]
  }.compact

  variables = { id:, code: lookup_code, attributes: }

  res = Client.new.query(@tenant_update_mutation, variables)
  raise ResponseError, res['data']['tenantUpdate']['errors'].join(',') if res['data']['tenantUpdate']['errors']

  res['data']['tenantUpdate']['tenant']
end