From 5fa67063f510e1a0b17891c373007aa45bea0f20 Mon Sep 17 00:00:00 2001 From: Shaun Hamilton Date: Wed, 4 Feb 2026 12:19:28 +0200 Subject: [PATCH] fix(api): update attempt with created moderation record (#64812) --- api/src/exam-environment/routes/exam-environment.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/api/src/exam-environment/routes/exam-environment.ts b/api/src/exam-environment/routes/exam-environment.ts index ef2db2bc0fb..575dac63232 100644 --- a/api/src/exam-environment/routes/exam-environment.ts +++ b/api/src/exam-environment/routes/exam-environment.ts @@ -687,7 +687,7 @@ async function postExamAttemptHandler( : 'Unknown attempt validation error'; logger.warn({ validExamAttemptError: message }, 'Invalid exam attempt.'); // As attempt is invalid, create moderation record to investigate or update existing record - await this.prisma.examEnvironmentExamModeration.upsert({ + const moderation = await this.prisma.examEnvironmentExamModeration.upsert({ where: { examAttemptId: latestAttempt.id }, create: { examAttemptId: latestAttempt.id, @@ -699,6 +699,17 @@ async function postExamAttemptHandler( } }); + // Link attempt with moderation id if it has not already been done + await this.prisma.examEnvironmentExamAttempt.update({ + where: { + id: latestAttempt.id, + examModerationId: null + }, + data: { + examModerationId: moderation.id + } + }); + void reply.code(400); return reply.send(ERRORS.FCC_EINVAL_EXAM_ENVIRONMENT_EXAM_ATTEMPT(message)); }