From bec85c23c8b2d9df55d81e007d1338f448ceb75b Mon Sep 17 00:00:00 2001 From: Bram Reyniers Date: Mon, 13 May 2024 16:16:18 +0200 Subject: [PATCH] fix subjects query --- frontend/src/components/home/cards/SubjectsCard.vue | 2 +- frontend/src/queries/Subject.ts | 5 +++-- frontend/src/services/subject.ts | 13 +++++-------- frontend/src/views/CreateProjectView.vue | 3 +-- frontend/src/views/subject/SubjectsView.vue | 11 +++++++++-- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/home/cards/SubjectsCard.vue b/frontend/src/components/home/cards/SubjectsCard.vue index 1364b42b..eb712afa 100644 --- a/frontend/src/components/home/cards/SubjectsCard.vue +++ b/frontend/src/components/home/cards/SubjectsCard.vue @@ -3,7 +3,7 @@

Error loading subjects

- + diff --git a/frontend/src/queries/Subject.ts b/frontend/src/queries/Subject.ts index bde216bd..e598543f 100644 --- a/frontend/src/queries/Subject.ts +++ b/frontend/src/queries/Subject.ts @@ -13,6 +13,7 @@ import { import { getSubjectProjects } from "@/services/project"; import type User from "@/models/User"; import type Subject from "@/models/Subject"; +import type { UserSubjectList } from "@/models/Subject"; import type Project from "@/models/Project"; function SUBJECT_QUERY_KEY(subjectId: number | string): (string | number)[] { @@ -65,8 +66,8 @@ export function useSubjectUuidQuery( /** * Query composable for fetching all subjects of the current user */ -export function useSubjectsQuery(): UseQueryReturnType { - return useQuery({ +export function useSubjectsQuery(): UseQueryReturnType { + return useQuery({ queryKey: SUBJECTS_QUERY_KEY(), queryFn: getSubjects, }); diff --git a/frontend/src/services/subject.ts b/frontend/src/services/subject.ts index d12e9719..fea50723 100644 --- a/frontend/src/services/subject.ts +++ b/frontend/src/services/subject.ts @@ -1,5 +1,6 @@ import type User from "@/models/User"; import type Subject from "@/models/Subject"; +import type { UserSubjectList } from "@/models/Subject"; import { authorized_fetch } from "@/services"; /** @@ -19,14 +20,10 @@ export async function getSubjectByUuid(subjectUuid: string): Promise { /** * Fetches all subjects the current user is enrolled in. */ -export async function getSubjects(): Promise { - const result = await authorized_fetch<{ as_instructor: Subject[]; as_student: Subject[] }>( - "/api/users/me/subjects", - { - method: "GET", - } - ); - return [...result.as_instructor, ...result.as_student]; +export async function getSubjects(): Promise { + return await authorized_fetch("/api/users/me/subjects", { + method: "GET", + }); } /** diff --git a/frontend/src/views/CreateProjectView.vue b/frontend/src/views/CreateProjectView.vue index d4ef1e87..e491032a 100644 --- a/frontend/src/views/CreateProjectView.vue +++ b/frontend/src/views/CreateProjectView.vue @@ -134,8 +134,7 @@ const assistants = computed( ); const subjects = computed( () => - // mySubjectsData.value?.as_instructor.map(({ name, id }) => ({ text: name, value: id })) || [] - subjectsData.value?.map(({ name, id }) => ({ text: name, value: id })) || [] + subjectsData.value?.as_instructor.map(({ name, id }) => ({ text: name, value: id })) || [] ); const groupProjectOptions = [ diff --git a/frontend/src/views/subject/SubjectsView.vue b/frontend/src/views/subject/SubjectsView.vue index df21e02e..88bd257a 100644 --- a/frontend/src/views/subject/SubjectsView.vue +++ b/frontend/src/views/subject/SubjectsView.vue @@ -2,6 +2,9 @@

Error: {{ error }}

+
+ Loading... +
@@ -12,7 +15,7 @@ { + return [...subjects.value!.as_student, ...subjects.value!.as_instructor] || []; +});