mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
bec610458c
Also: (bug) unable to create plan without partner (bug) unable to set plan price to a decimal number (bug) unable to create a plan without toggling the partner switch (quality) linted PlansService
25 lines
699 B
Ruby
25 lines
699 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Provides methods for Plan & PartnerPlan actions
|
|
class PlansService
|
|
class << self
|
|
def create(type, partner, params)
|
|
if params[:group_id] == 'all'
|
|
plans = type.constantize.create_for_all_groups(params)
|
|
return false unless plans
|
|
|
|
plans.each { |plan| partner.add_role :partner, plan } unless partner.nil?
|
|
{ plan_ids: plans.map(&:id) }
|
|
else
|
|
plan = type.constantize.new(params)
|
|
return { errors: plan.errors.full_messages } unless plan.save
|
|
|
|
partner&.add_role :partner, plan
|
|
{ plan_ids: [plan.id] }
|
|
end
|
|
rescue PaymentGatewayError => e
|
|
{ errors: e.message }
|
|
end
|
|
end
|
|
end
|