fix: update API endpoints and course marks page

This commit is contained in:
Rotimi Best
2025-12-05 11:11:37 +01:00
parent ac4fdf1dd3
commit 97d9e490b0
2 changed files with 97 additions and 82 deletions
@@ -49,16 +49,9 @@ export const POST: RequestHandler = async ({ request }) => {
throw new Error('Error fetching exercises'); throw new Error('Error fetching exercises');
} }
const formattedExercises = exercises.map((exercise) => ({
lesson_id: exercise.lesson_id,
exercise_id: exercise.id,
exercise_title: exercise.title,
points: exercise.points
}));
return json({ return json({
success: true, success: true,
data: formattedExercises data: exercises
}); });
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : 'Internal server error'; const message = error instanceof Error ? error.message : 'Internal server error';
@@ -18,7 +18,12 @@
import { profile } from '$lib/utils/store/user'; import { profile } from '$lib/utils/store/user';
import type { GroupPerson } from '$lib/utils/types'; import type { GroupPerson } from '$lib/utils/types';
import type { CurrentOrg } from '$lib/utils/types/org'; import type { CurrentOrg } from '$lib/utils/types/org';
import { Loading, OverflowMenu, OverflowMenuItem } from 'carbon-components-svelte'; import {
Loading,
OverflowMenu,
OverflowMenuItem,
SkeletonPlaceholder
} from 'carbon-components-svelte';
import AudioConsoleIcon from 'carbon-icons-svelte/lib/AudioConsole.svelte'; import AudioConsoleIcon from 'carbon-icons-svelte/lib/AudioConsole.svelte';
import Download from 'carbon-icons-svelte/lib/Download.svelte'; import Download from 'carbon-icons-svelte/lib/Download.svelte';
import jsPDF from 'jspdf'; import jsPDF from 'jspdf';
@@ -33,6 +38,7 @@
let lessonMapping = {}; // { lessonId: { exerciseId: exerciseTitle, ... }, ... } let lessonMapping = {}; // { lessonId: { exerciseId: exerciseTitle, ... }, ... }
let studentMarksByExerciseId = {}; // { groupMemberId: { exerciseId: `total_gotten/points`, ... }, ... } let studentMarksByExerciseId = {}; // { groupMemberId: { exerciseId: `total_gotten/points`, ... }, ... }
let isDownloading = false; let isDownloading = false;
let isLoading = false;
function calculateStudentTotal(studentExerciseData) { function calculateStudentTotal(studentExerciseData) {
if (!studentExerciseData) return 0; if (!studentExerciseData) return 0;
@@ -44,14 +50,19 @@
} }
async function firstRender(courseId: string) { async function firstRender(courseId: string) {
isLoading = true;
const { data: marks, error } = await fetchMarks(courseId); const { data: marks, error } = await fetchMarks(courseId);
if (error) { if (error) {
isLoading = false;
console.error('Error fetching marks', error); console.error('Error fetching marks', error);
snackbar.error('snackbar.marks.error'); snackbar.error('snackbar.marks.error');
return; return;
} }
if (!marks || !Array.isArray(marks)) return; if (!marks || !Array.isArray(marks)) {
isLoading = false;
return;
}
marks.forEach((mark) => { marks.forEach((mark) => {
const { groupmember_id, exercise_id, total_points_gotten } = mark; const { groupmember_id, exercise_id, total_points_gotten } = mark;
@@ -85,6 +96,8 @@
}; };
} }
}); });
isLoading = false;
} }
// TODO WRITE A REDIRECT FUNCTION FOR THIS THIS PAGE // TODO WRITE A REDIRECT FUNCTION FOR THIS THIS PAGE
@@ -238,6 +251,14 @@
</PageNav> </PageNav>
<PageBody width="w-full max-w-6xl md:w-11/12"> <PageBody width="w-full max-w-6xl md:w-11/12">
{#if isLoading}
<div class=" h-full w-full">
<SkeletonPlaceholder class="mb-4 h-8 w-full" />
<SkeletonPlaceholder class="mb-4 h-8 w-full" />
<SkeletonPlaceholder class="mb-4 h-8 w-full" />
<SkeletonPlaceholder class="mb-4 h-8 w-full" />
</div>
{:else}
<div id="tableContainer" class="table w-full rounded-md border border-gray-300"> <div id="tableContainer" class="table w-full rounded-md border border-gray-300">
<div class="flex items-center {borderBottomGrey}"> <div class="flex items-center {borderBottomGrey}">
<div class="box flex items-center p-3"> <div class="box flex items-center p-3">
@@ -318,6 +339,7 @@
</Box> </Box>
{/each} {/each}
</div> </div>
{/if}
</PageBody> </PageBody>
</RoleBasedSecurity> </RoleBasedSecurity>
</CourseContainer> </CourseContainer>