Class: CommandTower::Messaging::Endpoints::MarkInvalid

Inherits:
Object
  • Object
show all
Defined in:
app/services/command_tower/messaging/endpoints/mark_invalid.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_user_id:, endpoint_id:) ⇒ MarkInvalid

Returns a new instance of MarkInvalid.



11
12
13
14
# File 'app/services/command_tower/messaging/endpoints/mark_invalid.rb', line 11

def initialize(owner_user_id:, endpoint_id:)
  @owner_user_id = owner_user_id
  @endpoint_id = endpoint_id
end

Class Method Details

.call(owner_user_id:, endpoint_id:) ⇒ Object



7
8
9
# File 'app/services/command_tower/messaging/endpoints/mark_invalid.rb', line 7

def self.call(owner_user_id:, endpoint_id:)
  new(owner_user_id:, endpoint_id:).call
end

Instance Method Details

#callObject

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/command_tower/messaging/endpoints/mark_invalid.rb', line 16

def call
  record = Endpoint.for_owner(@owner_user_id).lock.find_by(id: @endpoint_id)
  raise NotFoundError, "endpoint not found" if record.nil?

  ChannelGate.assert_record_supported!(record)

  return SafeView.from_record(record) if record.lifecycle_state == "invalid"
  return SafeView.from_record(record) if record.lifecycle_state == "retired"

  Lifecycle.apply!(record, to: "invalid")
  record.save!
  SafeView.from_record(record)
end