Per review , Simplify creation of Voucher

We now check against known type to instanciate the correct voucher
instead of using a case
This commit is contained in:
Gaetan Craig-Riou
2023-07-18 13:24:41 +10:00
parent 3f63cfbc27
commit e6b53c0a42

View File

@@ -9,13 +9,11 @@ module Admin
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