Arie/serveme

View on GitHub
app/validators/reservations/server_is_available_validator.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

module Reservations
  class ServerIsAvailableValidator < ActiveModel::Validator
    def validate(record)
      return unless record.server && (record.collides_with_other_users_reservation? || record.collides_with_own_reservation_on_same_server?)

      record.errors.add(:server_id, 'already booked in the selected timeframe')
    end
  end
end