Skip to content

Commit f7a7543

Browse files
fixed wrong multitenancy implementation for vat rates; seeds updated
1 parent 77ae17e commit f7a7543

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

ecommerce/taxes/lib/taxes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Taxes
99
class Configuration
1010
def call(event_store, command_bus)
1111
command_bus.register(SetVatRate, SetVatRateHandler.new(event_store))
12-
command_bus.register(AddAvailableVatRate, AddAvailableVatRateHandler.new(event_store, command_bus))
12+
command_bus.register(AddAvailableVatRate, AddAvailableVatRateHandler.new(event_store))
1313
command_bus.register(RemoveAvailableVatRate, RemoveAvailableVatRateHandler.new(event_store))
1414
end
1515
end

ecommerce/taxes/lib/taxes/commands.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class SetVatRate < Infra::Command
77
class AddAvailableVatRate < Infra::Command
88
attribute :available_vat_rate_id, Infra::Types::UUID
99
attribute :vat_rate, Infra::Types::VatRate
10-
attribute :store_id, Infra::Types::UUID
1110
end
1211

1312
class RemoveAvailableVatRate < Infra::Command

ecommerce/taxes/lib/taxes/services.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ def call(cmd)
2020
class AddAvailableVatRateHandler
2121
include Infra::Retry
2222

23-
def initialize(event_store, command_bus)
23+
def initialize(event_store)
2424
@event_store = event_store
25-
@command_bus = command_bus
2625
end
2726

2827
def call(cmd)
@@ -32,13 +31,12 @@ def call(cmd)
3231

3332
expected_version = event ? event_store.position_in_stream(event.event_id, stream_name(cmd)) : -1
3433
event_store.publish(available_vat_rate_added_event(cmd), stream_name: stream_name(cmd), expected_version: expected_version)
35-
command_bus.call(Stores::RegisterVatRate.new(store_id: cmd.store_id, vat_rate_id: cmd.available_vat_rate_id))
3634
end
3735
end
3836

3937
private
4038

41-
attr_reader :event_store, :command_bus
39+
attr_reader :event_store
4240

4341
def last_available_vat_rate_event(vat_rate_code)
4442
event_store

rails_application/app/controllers/available_vat_rates_controller.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,22 @@ def destroy
5353
private
5454

5555
def add_available_vat_rate(code, rate, available_vat_rate_id)
56-
command_bus.(add_available_vat_rate_cmd(code, rate, available_vat_rate_id))
56+
ActiveRecord::Base.transaction do
57+
command_bus.(add_available_vat_rate_cmd(code, rate, available_vat_rate_id))
58+
command_bus.(register_vat_rate_cmd(available_vat_rate_id))
59+
end
5760
end
5861

5962
def add_available_vat_rate_cmd(code, rate, available_vat_rate_id)
6063
Taxes::AddAvailableVatRate.new(
6164
available_vat_rate_id: available_vat_rate_id,
62-
vat_rate: Infra::Types::VatRate.new(code: code, rate: rate),
65+
vat_rate: Infra::Types::VatRate.new(code: code, rate: rate)
66+
)
67+
end
68+
69+
def register_vat_rate_cmd(available_vat_rate_id)
70+
Stores::RegisterVatRate.new(
71+
vat_rate_id: available_vat_rate_id,
6372
store_id: current_store_id
6473
)
6574
end

rails_application/db/seeds.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@
4949
["20", 20],
5050
["10", 10]
5151
].each do |vat_rate|
52+
vat_rate_id = SecureRandom.uuid
5253
command_bus.call(
5354
Taxes::AddAvailableVatRate.new(
54-
available_vat_rate_id: SecureRandom.uuid,
55-
vat_rate: Infra::Types::VatRate.new(code: vat_rate[0], rate: vat_rate[1]),
55+
available_vat_rate_id: vat_rate_id,
56+
vat_rate: Infra::Types::VatRate.new(code: vat_rate[0], rate: vat_rate[1])
57+
)
58+
)
59+
command_bus.call(
60+
Stores::RegisterVatRate.new(
61+
vat_rate_id: vat_rate_id,
5662
store_id: store_1_id
5763
)
5864
)

0 commit comments

Comments
 (0)