Skip to content

Commit 0fd9f06

Browse files
feat(api): add moderation id to attempt (freeCodeCamp#64286)
1 parent a38caec commit 0fd9f06

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

api/__mocks__/exam-environment-exam.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export const generatedExam: ExamEnvironmentGeneratedExam = {
255255
export const examAttempt: ExamEnvironmentExamAttempt = {
256256
examId,
257257
generatedExamId: generatedExam.id,
258+
examModerationId: null,
258259
id: oid(),
259260
questionSets: [
260261
{

api/prisma/exam-environment.prisma

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,31 @@ type ExamEnvironmentTagConfig {
118118

119119
/// An attempt at an exam in the Exam Environment App
120120
model ExamEnvironmentExamAttempt {
121-
id String @id @default(auto()) @map("_id") @db.ObjectId
121+
id String @id @default(auto()) @map("_id") @db.ObjectId
122122
/// Foriegn key to user
123-
userId String @db.ObjectId
123+
userId String @db.ObjectId
124124
/// Foreign key to exam
125-
examId String @db.ObjectId
125+
examId String @db.ObjectId
126126
/// Foreign key to generated exam id
127-
generatedExamId String @db.ObjectId
127+
generatedExamId String @db.ObjectId
128+
/// Un-enforced foreign key to moderation
129+
examModerationId String? @db.ObjectId
128130
129131
questionSets ExamEnvironmentQuestionSetAttempt[]
130132
/// Time exam was started
131133
startTime DateTime
132134
/// Version of the record
133135
/// The default must be incremented by 1, if anything in the schema changes
134-
version Int @default(3)
136+
version Int @default(4)
135137
136138
// Relations
137-
user user @relation(fields: [userId], references: [id], onDelete: Cascade)
138-
exam ExamEnvironmentExam @relation(fields: [examId], references: [id], onDelete: Cascade)
139-
generatedExam ExamEnvironmentGeneratedExam @relation(fields: [generatedExamId], references: [id])
140-
ExamEnvironmentExamModeration ExamEnvironmentExamModeration[]
139+
user user @relation(fields: [userId], references: [id], onDelete: Cascade)
140+
exam ExamEnvironmentExam @relation(fields: [examId], references: [id], onDelete: Cascade)
141+
generatedExam ExamEnvironmentGeneratedExam @relation(fields: [generatedExamId], references: [id])
142+
// Ideally, there could be a way to add a one-way optional relation here, but Prisma does not allow that:
143+
// Error parsing attribute "@relation": The relation fields `examAttempt` on Model `ExamEnvironmentExamModeration` and `examModeration` on Model `ExamEnvironmentExamAttempt` both provide the `references` argument in the @relation attribute. You have to provide it only on one of the two fields.
144+
// examModeration ExamEnvironmentExamModeration? @relation(fields: [examModerationId], references: [id])
145+
examEnvironmentExamModeration ExamEnvironmentExamModeration?
141146
}
142147

143148
type ExamEnvironmentQuestionSetAttempt {

api/src/exam-environment/routes/exam-environment.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ describe('/exam-environment/', () => {
590590
userId: defaultUserId,
591591
examId: mock.examId,
592592
generatedExamId: generatedExam!.id,
593+
examModerationId: null,
593594
questionSets: [],
594595
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
595596
startTime: expect.any(Date),

api/src/exam-environment/routes/exam-environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ async function postExamGeneratedExamHandler(
458458
userId: user.id,
459459
examId: exam.id,
460460
generatedExamId: generatedExam.id,
461+
examModerationId: null,
461462
startTime: new Date(),
462463
questionSets: []
463464
}

api/src/exam-environment/utils/exam-environment.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ describe('Exam Environment Schema', () => {
518518
data: {
519519
examId: oid(),
520520
generatedExamId: oid(),
521+
examModerationId: null,
521522
questionSets: [
522523
{
523524
id: oid(),

0 commit comments

Comments
 (0)