diff --git a/frontend/src/controllers/questions.ts b/frontend/src/controllers/questions.ts index 86f4a56d..bca464ae 100644 --- a/frontend/src/controllers/questions.ts +++ b/frontend/src/controllers/questions.ts @@ -18,6 +18,10 @@ export class QuestionController extends BaseController { this.loId = loId; } + async getAllGroup(classId: string, assignmentId: string, forStudent: string, full = true): Promise { + return this.get("/", { lang: this.loId.language, full, classId, assignmentId, forStudent }); + } + async getAll(full = true): Promise { return this.get("/", { lang: this.loId.language, full }); } diff --git a/frontend/src/queries/questions.ts b/frontend/src/queries/questions.ts index 66f1492f..a8fc485e 100644 --- a/frontend/src/queries/questions.ts +++ b/frontend/src/queries/questions.ts @@ -17,6 +17,16 @@ export function questionsQueryKey( return ["questions", loId.hruid, loId.version!, loId.language, full]; } +export function questionsGroupQueryKey( + loId: LearningObjectIdentifierDTO, + classId: string, + assignmentId: string, + student: string, + full: boolean, +): [string, string, number, string, boolean] { + return ["questions", loId.hruid, loId.version!, loId.language, full, classId, assignmentId, student]; +} + export function questionQueryKey(questionId: QuestionId): [string, string, number, string, number] { const loId = questionId.learningObjectIdentifier; return ["question", loId.hruid, loId.version!, loId.language, questionId.sequenceNumber]; @@ -33,6 +43,20 @@ export function useQuestionsQuery( }); } +export function useQuestionsGroupQuery( + loId: MaybeRefOrGetter, + classId: MaybeRefOrGetter, + assignmentId: MaybeRefOrGetter, + student: MaybeRefOrGetter, + full: MaybeRefOrGetter = true, +): UseQueryReturnType { + return useQuery({ + queryKey: computed(() => questionsGroupQueryKey(toValue(loId), toValue(full), toValue(classId), toValue(assignmentId), toValue(student))), + queryFn: async () => new QuestionController(toValue(loId)).getAllGroup( toValue(classId), toValue(assignmentId), toValue(student),toValue(full)), + enabled: () => Boolean(toValue(loId)), + }); +} + export function useQuestionQuery( questionId: MaybeRefOrGetter, ): UseQueryReturnType { diff --git a/frontend/src/views/learning-paths/LearningPathPage.vue b/frontend/src/views/learning-paths/LearningPathPage.vue index c41f6063..1618e6ac 100644 --- a/frontend/src/views/learning-paths/LearningPathPage.vue +++ b/frontend/src/views/learning-paths/LearningPathPage.vue @@ -13,13 +13,11 @@ import authService from "@/services/auth/auth-service.ts"; import { LearningPathNode } from "@/data-objects/learning-paths/learning-path-node.ts"; import LearningPathGroupSelector from "@/views/learning-paths/LearningPathGroupSelector.vue"; - import { useCreateQuestionMutation, useQuestionsQuery } from "@/queries/questions"; + import {useQuestionsGroupQuery, useQuestionsQuery} from "@/queries/questions"; import type { QuestionsResponse } from "@/controllers/questions"; import type { LearningObjectIdentifierDTO } from "@dwengo-1/common/interfaces/learning-content"; import QandA from "@/components/QandA.vue"; import type { QuestionDTO } from "@dwengo-1/common/interfaces/question"; - import { useStudentAssignmentsQuery, useStudentGroupsQuery } from "@/queries/students"; - import type { AssignmentDTO } from "@dwengo-1/common/interfaces/assignment"; import QuestionNotification from "@/components/QuestionNotification.vue"; import QuestionBox from "@/components/QuestionBox.vue"; import { AccountType } from "@dwengo-1/common/util/account-types"; @@ -78,16 +76,32 @@ return currentIndex < nodesList.value?.length ? nodesList.value?.[currentIndex - 1] : undefined; }); - const getQuestionsQuery = useQuestionsQuery( - computed( - () => - ({ - language: currentNode.value?.language, - hruid: currentNode.value?.learningobjectHruid, - version: currentNode.value?.version, - }) as LearningObjectIdentifierDTO, - ), - ); + + + let getQuestionsQuery; + + + + if (authService.authState.activeRole === AccountType.Student) { + getQuestionsQuery = useQuestionsGroupQuery( + computed(() => ({ + language: currentNode.value?.language, + hruid: currentNode.value?.learningobjectHruid, + version: currentNode.value?.version, + }) as LearningObjectIdentifierDTO), + computed(() => query.value.classId ?? ""), + computed(() => query.value.assignmentNo ?? ""), + computed(() => authService.authState.user?.profile.preferred_username ?? "") + ); + } else { + getQuestionsQuery = useQuestionsQuery( + computed(() => ({ + language: currentNode.value?.language, + hruid: currentNode.value?.learningobjectHruid, + version: currentNode.value?.version, + }) as LearningObjectIdentifierDTO) + ); + } const navigationDrawerShown = ref(true); @@ -147,18 +161,10 @@ }); } - const studentAssignmentsQueryResult = useStudentAssignmentsQuery( - authService.authState.user?.profile.preferred_username, - ); - const loID: LearningObjectIdentifierDTO = { hruid: props.learningObjectHruid as string, language: props.language, }; - const createQuestionMutation = useCreateQuestionMutation(loID); - const groupsQueryResult = useStudentGroupsQuery(authService.authState.user?.profile.preferred_username); - - const questionInput = ref(""); const discussionLink = computed( () =>