mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-04-10 00:53:51 +02:00
users_credits/manager service: initializing service, you can pass a plan to simulate that user have that plan
This commit is contained in:
parent
74e2d170bf
commit
aee8146040
@ -7,14 +7,14 @@ module UsersCredits
|
|||||||
extend Forwardable
|
extend Forwardable
|
||||||
attr_reader :manager
|
attr_reader :manager
|
||||||
|
|
||||||
def initialize(reservation: nil, user: nil)
|
def initialize(reservation: nil, user: nil, plan: nil)
|
||||||
if user
|
if user
|
||||||
@manager = Managers::User.new(user)
|
@manager = Managers::User.new(user)
|
||||||
elsif reservation
|
elsif reservation
|
||||||
if reservation.reservable_type == "Training"
|
if reservation.reservable_type == "Training"
|
||||||
@manager = Managers::Training.new(reservation)
|
@manager = Managers::Training.new(reservation, plan)
|
||||||
elsif reservation.reservable_type == "Machine"
|
elsif reservation.reservable_type == "Machine"
|
||||||
@manager = Managers::Machine.new(reservation)
|
@manager = Managers::Machine.new(reservation, plan)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -38,13 +38,14 @@ module UsersCredits
|
|||||||
class Reservation
|
class Reservation
|
||||||
attr_reader :reservation
|
attr_reader :reservation
|
||||||
|
|
||||||
def initialize(reservation)
|
def initialize(reservation, plan)
|
||||||
@reservation = reservation
|
@reservation = reservation
|
||||||
@already_updated = false
|
@already_updated = false
|
||||||
|
@plan = plan
|
||||||
end
|
end
|
||||||
|
|
||||||
def plan
|
def plan
|
||||||
user.subscribed_plan
|
@plan || user.subscribed_plan
|
||||||
end
|
end
|
||||||
|
|
||||||
def user
|
def user
|
||||||
@ -129,7 +130,7 @@ module UsersCredits
|
|||||||
# if there is a training_credit defined for this plan and this training
|
# if there is a training_credit defined for this plan and this training
|
||||||
if training_credit = plan.training_credits.find_by(creditable_id: reservation.reservable_id)
|
if training_credit = plan.training_credits.find_by(creditable_id: reservation.reservable_id)
|
||||||
# if user has not used all the plan credits
|
# if user has not used all the plan credits
|
||||||
if user.training_credits.count < plan.training_credit_nb
|
if user.training_credits.where(plan: plan).count < plan.training_credit_nb
|
||||||
return true, training_credit
|
return true, training_credit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user