Skip to content

Commit

Permalink
refactor transaction function to take in count the roallback
Browse files Browse the repository at this point in the history
  • Loading branch information
lyna-azerouk committed Nov 12, 2024
1 parent 9dacb00 commit 23284eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
db:
image: postgres
environment:
POSTGRES_USER: ecommerce_user
POSTGRES_USER: ecomerce_user
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ecommerce_development
ports:
Expand All @@ -15,7 +15,7 @@ services:
app:
build: .
environment:
DATABASE_URL: postgres://ecommerce_user:postgres@db:5432/ecommerce_development
DATABASE_URL: postgres://ecomerce_user:postgres@db:5432/ecommerce_development
ports:
- "9292:9292"
depends_on:
Expand Down
9 changes: 8 additions & 1 deletion api/transactions/base_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ class BaseTransaction
include Dry::Transaction

def self.call(*args, &block)
new.call(*args, &block)
transaction_result = nil

ActiveRecord::Base.transaction do
transaction_result = new.call(*args, &block)

raise ActiveRecord::Rollback unless transaction_result.failure.nil?
end
transaction_result
end
end

0 comments on commit 23284eb

Please sign in to comment.