Sha256: 01d1594fde7074d3c0bbc2450ce834d276b446006fe9201e25393c971903a106

Contents?: true

Size: 885 Bytes

Versions: 1

Compression:

Stored size: 885 Bytes

Contents

module Ecom
  module Core
    class BookingRequest < ApplicationRecord
      DRAFT = 'Draft'.freeze
      UNDER_REVIEW = 'Under Review'.freeze
      APPROVED = 'Approved'.freeze
      REJECTED = 'Rejected'.freeze

      STATUSES = [DRAFT, UNDER_REVIEW, APPROVED, REJECTED].freeze
      belongs_to :equipment
      belongs_to :country, optional: true
      belongs_to :requested_by, class_name: 'Ecom::Core::User'
      belongs_to :approved_by, class_name: 'Ecom::Core::User', optional: true

      validates :start_date, :end_date, :quantity, :status, presence: true
      validates :status, inclusion: STATUSES
      validates_with DateRangeValidator

      scope :by_status, ->(status) { where(status: status) }

      def validate_date_range
        errors.add(:end_date, 'cannot be before start date') if start_date && end_date && start_date > end_date
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ecom_core-1.2.12 app/models/ecom/core/booking_request.rb