fix(api): can take exam if attempt not expired (#62543)

This commit is contained in:
Shaun Hamilton
2025-10-07 16:46:52 +02:00
committed by GitHub
parent 5228e6818c
commit cf6dbc0218
2 changed files with 12 additions and 9 deletions
+2 -8
View File
@@ -14,7 +14,6 @@ model ExamEnvironmentExam {
/// The default must be incremented by 1, if anything in the schema changes
version Int @default(2)
// Relations
generatedExams ExamEnvironmentGeneratedExam[]
examAttempts ExamEnvironmentExamAttempt[]
@@ -140,7 +139,6 @@ model ExamEnvironmentExamAttempt {
/// The default must be incremented by 1, if anything in the schema changes
version Int @default(2)
// Relations
user user @relation(fields: [userId], references: [id], onDelete: Cascade)
exam ExamEnvironmentExam @relation(fields: [examId], references: [id], onDelete: Cascade)
@@ -180,7 +178,6 @@ model ExamEnvironmentGeneratedExam {
/// The default must be incremented by 1, if anything in the schema changes
version Int @default(1)
// Relations
exam ExamEnvironmentExam @relation(fields: [examId], references: [id], onDelete: Cascade)
EnvExamAttempt ExamEnvironmentExamAttempt[]
@@ -208,7 +205,6 @@ model ExamEnvironmentChallenge {
version Int @default(1)
exam ExamEnvironmentExam @relation(fields: [examId], references: [id], onDelete: Cascade)
}
@@ -220,7 +216,6 @@ model ExamEnvironmentAuthorizationToken {
userId String @unique @db.ObjectId
version Int @default(1)
// Relations
user user @relation(fields: [userId], references: [id], onDelete: Cascade)
}
@@ -238,12 +233,11 @@ model ExamEnvironmentExamModeration {
/// Foreign key to moderator. This is `null` until the item is moderated.
moderatorId String? @db.ObjectId
/// Date the exam attempt was added to the moderation queue
/// Date the exam attempt expired
submissionDate DateTime @default(now()) @db.Date
/// Version of the record
/// The default must be incremented by 1, if anything in the schema changes
version Int @default(1)
version Int @default(2)
// Relations
examAttempt ExamEnvironmentExamAttempt @relation(fields: [examAttemptId], references: [id], onDelete: Cascade)
@@ -823,8 +823,17 @@ async function getExams(
: exam.config.retakeTimeInMS;
const retakeDateInMS =
lastAttemptStartTime + examTotalTimeInMS + examRetakeTimeInMS;
const isRetakeTimePassed = Date.now() > retakeDateInMS;
const lastAttemptExpired =
Date.now() > lastAttemptStartTime + examTotalTimeInMS;
if (!lastAttemptExpired) {
logger.info(`Exam ${exam.id} in progress.`);
availableExam.canTake = true;
availableExams.push(availableExam);
continue;
}
const isRetakeTimePassed = Date.now() > retakeDateInMS;
if (!isRetakeTimePassed) {
logger.info(`Time until retake: ${retakeDateInMS - Date.now()} [ms]`);
availableExam.canTake = false;