mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(api): can take exam if attempt not expired (#62543)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user