Skip to content

Commit

Permalink
remove time entry validation until we sunset team maker
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Apr 1, 2024
1 parent 61e0414 commit 8dd5c91
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions app/models/time_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ class TimeEntry < ApplicationRecord
validates :date, presence: true

validates :date, uniqueness: { scope: %i[user_id statement_of_work_id] }
validate :assignment_must_exist_in_period
# validate :assignment_must_exist_in_period

scope :active_in_period, ->(start_date, end_date) { where('date <= ? AND date >= ?', end_date, start_date) }

def assignment_must_exist_in_period
assignment_exists = Assignment.joins(:requirement)
.where(user_id:)
.where(requirements: { statement_of_work_id: })
.exists?(['? >= assignments.start_date AND ? <= assignments.end_date', date, date])

# If not, add an error.
return if assignment_exists

errors.add(:base,
"There is no valid assignment for the user
and statement of work in this period: #{user.name}
date:#{date} for the SOW: #{statement_of_work.name}
in the project #{statement_of_work.project.name}")
end
# def assignment_must_exist_in_period
# assignment_exists = Assignment.joins(:requirement)
# .where(user_id:)
# .where(requirements: { statement_of_work_id: })
# .exists?(['? >= assignments.start_date AND ? <= assignments.end_date', date, date])
#
# # If not, add an error.
# return if assignment_exists
#
# errors.add(:base,
# "There is no valid assignment for the user
# and statement of work in this period: #{user.name}
# date:#{date} for the SOW: #{statement_of_work.name}
# in the project #{statement_of_work.project.name}")
# end
end

0 comments on commit 8dd5c91

Please sign in to comment.