Skip to content

Commit

Permalink
Per review , Simplify creation of Voucher
Browse files Browse the repository at this point in the history
We now check against known type to instanciate the correct voucher
instead of using a case
  • Loading branch information
rioug committed Jul 24, 2023
1 parent d4a2fde commit 229ae91
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/controllers/admin/vouchers_controller.rb
Expand Up @@ -9,13 +9,11 @@ def new
end

def create
case params[:vouchers_flat_rate][:voucher_type]
when "Vouchers::FlatRate"
@voucher =
Vouchers::FlatRate.create(permitted_resource_params.merge(enterprise: @enterprise))
when "Vouchers::PercentageRate"
@voucher =
Vouchers::PercentageRate.create(permitted_resource_params.merge(enterprise: @enterprise))
voucher_type = params[:vouchers_flat_rate][:voucher_type]
if Voucher::TYPES.include?(voucher_type)
@voucher = voucher_type.safe_constantize.create(
permitted_resource_params.merge(enterprise: @enterprise)
)
else
@voucher.errors.add(:type)
return render_error
Expand Down

0 comments on commit 229ae91

Please sign in to comment.