lecture-attendance-manager/app/models/work_item.rb
Joshua Coles c8b688ce57
All checks were successful
Build and Publish Docker Container / build (push) Successful in 5m43s
Flesh out work items in the UI
2023-10-08 16:06:07 +01:00

40 lines
831 B
Ruby

class WorkItem < ApplicationRecord
belongs_to :course
has_many :tracked_time_entries, dependent: :destroy, as: :subject
validate :date_orderings
include Trackable, CourseItem
def start_time
available_from
end
def completed?
completed_at.present?
end
def complete!
update(completed_at: Time.now)
end
def workable?
available_from.past? && !completed?
end
def started?
!tracked_time_entries.empty?
end
private
def date_orderings
if due_at.present? && available_from.present? && due_at < available_from
errors.add(:due_at, "can't be before date work item is available")
end
if completed_at.present? && available_from.present? && completed_at < available_from
errors.add(:completed_at, "can't be before date work item is available")
end
end
end