-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
230 Initial commit of evaluation and score backend
- Loading branch information
1 parent
65f6437
commit c003e41
Showing
11 changed files
with
804 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: evaluations | ||
# | ||
# id :bigint not null, primary key | ||
# user_id :bigint not null | ||
# evaluation_form_id :bigint not null | ||
# status :integer default("not_started"), not null | ||
# total_score :integer default(nil) | ||
# additional_comments :text | ||
# revision_comments :text | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class Evaluation < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :evaluation_form | ||
has_many :evaluation_scores, dependent: :destroy | ||
|
||
enum :status, { | ||
not_started: 0, | ||
recused: 1, | ||
in_progress: 2, | ||
completed: 3 | ||
} | ||
|
||
validates :total_score, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true | ||
validates :additional_comments, length: { maximum: 3000, message: "cannot exceed 3000 characters" }, | ||
allow_nil: true | ||
validates :revision_comments, length: { maximum: 3000, message: "cannot exceed 3000 characters" }, | ||
allow_nil: true | ||
|
||
validate :user_has_valid_role | ||
|
||
private | ||
|
||
def user_has_valid_role | ||
return if User::VALID_EVALUATOR_ROLES.include?(user.role) | ||
|
||
errors.add(:user, "must have a valid evaluator role") | ||
end | ||
end |
Oops, something went wrong.