summaryrefslogtreecommitdiff
path: root/app/services/addresses/address_services_base.rb
blob: 9b7f9f3c96eea084e95e5ed8925d0b1dc7eac534 (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
# frozen_string_literal: true

module Addresses
  # The base class for all addresses' services.
  class AddressServicesBase
    def initialize(user_account, params)
      @user_account = user_account
      @params = params
    end

    def error_messages
      @address.errors.as_json
    end

    private

    def already_existing_address
      @already_existing_address ||= Address.find_by(@params)
    end

    def add_address_to_user_addresses
      already_existing_address.user_accounts << @user_account
      already_existing_address.save
    end
  end
end