From 76c9fa9d48c68f0b64f860972db53743d1cfa01c Mon Sep 17 00:00:00 2001 From: Shaun Hamilton Date: Thu, 31 Jul 2025 16:54:29 +0200 Subject: [PATCH] feat(api): add attempts routes to user (#61362) Co-authored-by: Tom <20648924+moT01@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> --- .../routes/exam-environment.ts | 4 ++-- api/src/routes/protected/user.ts | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api/src/exam-environment/routes/exam-environment.ts b/api/src/exam-environment/routes/exam-environment.ts index cf4be5f401c..5c0adc3cbd7 100644 --- a/api/src/exam-environment/routes/exam-environment.ts +++ b/api/src/exam-environment/routes/exam-environment.ts @@ -812,7 +812,7 @@ async function getExams( * * If an attempt is completed, the result is included. */ -async function getExamAttemptsHandler( +export async function getExamAttemptsHandler( this: FastifyInstance, req: UpdateReqType, reply: FastifyReply @@ -872,7 +872,7 @@ async function getExamAttemptsHandler( * * If the attempt is completed, the result is included. */ -async function getExamAttemptHandler( +export async function getExamAttemptHandler( this: FastifyInstance, req: UpdateReqType, reply: FastifyReply diff --git a/api/src/routes/protected/user.ts b/api/src/routes/protected/user.ts index 82b5dc33dd6..8541c70c97a 100644 --- a/api/src/routes/protected/user.ts +++ b/api/src/routes/protected/user.ts @@ -6,6 +6,7 @@ import jwt from 'jsonwebtoken'; import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'; import * as schemas from '../../schemas'; +import * as examEnvironmentSchemas from '../../exam-environment/schemas'; import { createResetProperties } from '../../utils/create-user'; import { customNanoid } from '../../utils/ids'; import { encodeUserToken } from '../../utils/tokens'; @@ -27,6 +28,10 @@ import { ProgressTimestamp } from '../../utils/progress'; import { JWT_SECRET } from '../../utils/env'; +import { + getExamAttemptHandler, + getExamAttemptsHandler +} from '../../exam-environment/routes/exam-environment'; /** * Helper function to get the api url from the shared transcript link. @@ -475,6 +480,21 @@ export const userRoutes: FastifyPluginCallbackTypebox = ( examEnvironmentTokenHandler ); + fastify.get( + '/user/exam-environment/exam/attempts', + { + schema: examEnvironmentSchemas.examEnvironmentGetExamAttempts + }, + getExamAttemptsHandler + ); + fastify.get( + '/user/exam-environment/exam/attempt/:attemptId', + { + schema: examEnvironmentSchemas.examEnvironmentGetExamAttempt + }, + getExamAttemptHandler + ); + done(); };