Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/models/tutor_time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class TutorTime < ApplicationRecord
belongs_to :user
belongs_to :task

validates :user_id, presence: true
validates :task_id, presence: true
validates :time_spent, presence: true, numericality: { greater_than_or_equal_to: 0.0 }

def time_spent_in_hours
(time_spent.to_f / 60.0).round(2)
end
end
10 changes: 10 additions & 0 deletions db/migrate/20250324073540_create_tutor_times.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateTutorTimes < ActiveRecord::Migration[7.1]
def change
create_table :tutor_times do |t|
t.references :user, null: false, foreign_key: { on_delete: :cascade }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the "user" here a tutor (staff) that is assigned within a unit? You could probably reference the staff from the unit_roles table instead, implying that we're referencing staff here and not students

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @b0ink :), I believe this would be a tutor, I can push up a change shortly.

Im assuming I would also have to change the model then too right to include the following:

class TutorTime < ApplicationRecord
...
  belongs_to :unit_role
  has_one :user, through: :unit_role
....

t.references :task, null: false, foreign_key: { on_delete: :cascade }
t.decimal :time_spent, precision: 10, scale: 2, null: false, default: 0.0
t.timestamps
end
end
end
14 changes: 13 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_05_28_223908) do
ActiveRecord::Schema[7.1].define(version: 2025_03_24_073540) do
create_table "activity_types", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t|
t.string "name", null: false
t.string "abbreviation", null: false
Expand Down Expand Up @@ -394,6 +394,16 @@
t.index ["tii_task_similarity_id"], name: "index_tii_submissions_on_tii_task_similarity_id"
end

create_table "tutor_times", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.bigint "user_id", null: false
t.bigint "task_id", null: false
t.decimal "time_spent", precision: 10, scale: 2, default: "0.0", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["task_id"], name: "index_tutor_times_on_task_id"
t.index ["user_id"], name: "index_tutor_times_on_user_id"
end

create_table "tutorial_enrolments", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
Expand Down Expand Up @@ -531,4 +541,6 @@
t.index ["user_id"], name: "index_webcals_on_user_id", unique: true
end

add_foreign_key "tutor_times", "tasks", on_delete: :cascade
add_foreign_key "tutor_times", "users", on_delete: :cascade
end