blob: fe26b0571e0f4f6edc4e1110e9d44edf9d6ce393 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# frozen_string_literal: true
module Addresses
# The service for address creation.
class UpdateAddressService < AddressServicesBase
attr_reader :address
def initialize(user_account, address_id, params)
super(user_account, params)
@address_id = address_id
end
def call
@address = @user_account.addresses.find_by(id: @address_id)
return :not_found if @address.nil?
if already_existing_address.nil?
return :unprocessable_entity unless @address.update(@params)
else
add_address_to_user_addresses
@address.user_account_addresses.find_by(user_account_id: @user_account.id).destroy
@address.destroy if @address.user_accounts.count.zero?
@address = already_existing_address
end
end
end
end
|