1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-27 21:54:27 +01:00
fab-manager/app/validators/reservation_slot_subscription_validator.rb
Sylvain c7a59c8cb7 WIP: refactoring to singularize the booking process
We need to achieve only one process for all booking, not one for subscription, one for reservations, etc.
Moreover we must store one object per invoice_item/payment_schedule_object and stop using Invoice.invoiced or PaymentSchedule.scheduled
2021-05-21 18:25:18 +02:00

18 lines
642 B
Ruby

# frozen_string_literal: true
class ReservationSlotSubscriptionValidator < ActiveModel::Validator
def validate(record)
record.slots.each do |s|
unless s.availability.plan_ids.empty?
if record.user.subscribed_plan && s.availability.plan_ids.include?(record.user.subscribed_plan.id)
elsif s.availability.plan_ids.include?(record.plan_id)
else
# TODO, this validation requires to check if the operator is privileged.
# Meanwhile we can't check this, we disable the validation
record.errors[:slots] << 'slot is restrict for subscriptions'
end
end
end
end
end