From 5536136b215ba7b05df8a168e69c919e00fb43e0 Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 10:53:40 +0200 Subject: [PATCH 01/17] chore: make services throw errors to caller if requested --- .../src/composables/services/admin.service.ts | 16 ++-- .../composables/services/assistant.service.ts | 32 +++---- .../composables/services/course.service.ts | 44 ++++++---- .../composables/services/docker.service.ts | 23 ++--- .../services/extra_checks.service.ts | 11 +-- .../composables/services/faculty.service.ts | 16 ++-- .../src/composables/services/group.service.ts | 20 +++-- frontend/src/composables/services/helpers.ts | 84 ++++++++++++------- .../composables/services/project.service.ts | 35 ++++---- .../services/structure_check.service.ts | 16 ++-- .../composables/services/student.service.ts | 40 ++++----- .../services/submission.service.ts | 20 ++--- .../services/submission_status.service.ts | 4 +- .../composables/services/teacher.service.ts | 32 +++---- .../src/composables/services/users.service.ts | 20 +++-- 15 files changed, 234 insertions(+), 179 deletions(-) diff --git a/frontend/src/composables/services/admin.service.ts b/frontend/src/composables/services/admin.service.ts index 58db0007..485b3bb3 100644 --- a/frontend/src/composables/services/admin.service.ts +++ b/frontend/src/composables/services/admin.service.ts @@ -16,17 +16,17 @@ export function useAdmin(): AdminState { const admins = ref(null); const admin = ref(null); - async function getAdminByID(id: string): Promise { + async function getAdminByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.admins.retrieve.replace('{id}', id); - await get(endpoint, admin, User.fromJSON); + await get(endpoint, admin, User.fromJSON, selfprocessError); } - async function getAdmins(): Promise { + async function getAdmins(selfprocessError: boolean = true): Promise { const endpoint = endpoints.admins.index; - await getList(endpoint, admins, User.fromJSON); + await getList(endpoint, admins, User.fromJSON, selfprocessError); } - async function createAdmin(user: User): Promise { + async function createAdmin(user: User, selfprocessError: boolean = true): Promise { const endpoint = endpoints.admins.index; await create( endpoint, @@ -35,12 +35,14 @@ export function useAdmin(): AdminState { }, admin, User.fromJSON, + undefined, + selfprocessError ); } - async function deleteAdmin(id: string): Promise { + async function deleteAdmin(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.admins.retrieve.replace('{id}', id); - await deleteId(endpoint, admin, User.fromJSON); + await deleteId(endpoint, admin, User.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index 70690cf6..7a731beb 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -29,37 +29,37 @@ export function useAssistant(): AssistantState { const response = ref(null); const assistantPagination = ref | null>(null); - async function getAssistantByID(id: string): Promise { + async function getAssistantByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.assistants.retrieve.replace('{id}', id); - await get(endpoint, assistant, Assistant.fromJSON); + await get(endpoint, assistant, Assistant.fromJSON, selfprocessError); } - async function getAssistantsByCourse(courseId: string): Promise { + async function getAssistantsByCourse(courseId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); - await getList(endpoint, assistants, Assistant.fromJSON); + await getList(endpoint, assistants, Assistant.fromJSON, selfprocessError); } - async function getAssistants(): Promise { + async function getAssistants(selfprocessError: boolean = true): Promise { const endpoint = endpoints.assistants.index; - await getList(endpoint, assistants, Assistant.fromJSON); + await getList(endpoint, assistants, Assistant.fromJSON, selfprocessError); } - async function searchAssistants(filters: Filter, page: number, pageSize: number): Promise { + async function searchAssistants(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { const endpoint = endpoints.assistants.search; - await getPaginatedList(endpoint, filters, page, pageSize, assistantPagination, Assistant.fromJSON); + await getPaginatedList(endpoint, filters, page, pageSize, assistantPagination, Assistant.fromJSON, selfprocessError); } - async function assistantJoinCourse(courseId: string, assistantId: string): Promise { + async function assistantJoinCourse(courseId: string, assistantId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); - await create(endpoint, { assistant: assistantId }, response, Response.fromJSON); + await create(endpoint, { assistant: assistantId }, response, Response.fromJSON, undefined, selfprocessError); } - async function assistantLeaveCourse(courseId: string, assistantId: string): Promise { + async function assistantLeaveCourse(courseId: string, assistantId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); - await deleteIdWithData(endpoint, { assistant: assistantId }, response, Response.fromJSON); + await deleteIdWithData(endpoint, { assistant: assistantId }, response, Response.fromJSON, selfprocessError); } - async function createAssistant(user: User): Promise { + async function createAssistant(user: User, selfprocessError: boolean = true): Promise { const endpoint = endpoints.assistants.index; await create( endpoint, @@ -68,12 +68,14 @@ export function useAssistant(): AssistantState { }, assistant, Assistant.fromJSON, + undefined, + selfprocessError ); } - async function deleteAssistant(id: string): Promise { + async function deleteAssistant(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.assistants.retrieve.replace('{id}', id); - await deleteId(endpoint, assistant, Assistant.fromJSON); + await deleteId(endpoint, assistant, Assistant.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/course.service.ts b/frontend/src/composables/services/course.service.ts index 96ae28cb..8cd52a87 100644 --- a/frontend/src/composables/services/course.service.ts +++ b/frontend/src/composables/services/course.service.ts @@ -29,37 +29,37 @@ export function useCourses(): CoursesState { const course = ref(null); const response = ref(null); - async function getCourseByID(id: string): Promise { + async function getCourseByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.retrieve.replace('{id}', id); - await get(endpoint, course, Course.fromJSON); + await get(endpoint, course, Course.fromJSON, selfprocessError); } - async function getCourses(): Promise { + async function getCourses(selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.index; - await getList(endpoint, courses, Course.fromJSON); + await getList(endpoint, courses, Course.fromJSON, selfprocessError); } - async function searchCourses(filters: Filter, page: number, pageSize: number): Promise { + async function searchCourses(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.search; - await getPaginatedList(endpoint, filters, page, pageSize, pagination, Course.fromJSON); + await getPaginatedList(endpoint, filters, page, pageSize, pagination, Course.fromJSON, selfprocessError); } - async function getCoursesByStudent(studentId: string): Promise { + async function getCoursesByStudent(studentId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.byStudent.replace('{studentId}', studentId); - await getList(endpoint, courses, Course.fromJSON); + await getList(endpoint, courses, Course.fromJSON, selfprocessError); } - async function getCoursesByTeacher(teacherId: string): Promise { + async function getCoursesByTeacher(teacherId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.byTeacher.replace('{teacherId}', teacherId); - await getList(endpoint, courses, Course.fromJSON); + await getList(endpoint, courses, Course.fromJSON, selfprocessError); } - async function getCourseByAssistant(assistantId: string): Promise { + async function getCourseByAssistant(assistantId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.byAssistant.replace('{assistantId}', assistantId); - await getList(endpoint, courses, Course.fromJSON); + await getList(endpoint, courses, Course.fromJSON, selfprocessError); } - async function createCourse(courseData: Course): Promise { + async function createCourse(courseData: Course, selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.index; await create( endpoint, @@ -74,10 +74,12 @@ export function useCourses(): CoursesState { }, course, Course.fromJSON, + undefined, + selfprocessError ); } - async function updateCourse(courseData: Course): Promise { + async function updateCourse(courseData: Course, selfprocessError: boolean = true): Promise { // Endpoint to update is same as retrieve const endpoint = endpoints.courses.retrieve.replace('{id}', courseData.id); @@ -91,10 +93,12 @@ export function useCourses(): CoursesState { private_course: courseData.private_course, }, response, + undefined, + selfprocessError ); } - async function cloneCourse(courseId: string, cloneAssistants: boolean, cloneTeachers: boolean): Promise { + async function cloneCourse(courseId: string, cloneAssistants: boolean, cloneTeachers: boolean, selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.clone.replace('{courseId}', courseId); await create( endpoint, @@ -104,15 +108,17 @@ export function useCourses(): CoursesState { }, course, Course.fromJSON, + undefined, + selfprocessError ); } - async function deleteCourse(id: string): Promise { + async function deleteCourse(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.retrieve.replace('{id}', id); - await deleteId(endpoint, course, Course.fromJSON); + await deleteId(endpoint, course, Course.fromJSON, selfprocessError); } - async function activateInvitationLink(courseId: string, linkDuration: number): Promise { + async function activateInvitationLink(courseId: string, linkDuration: number, selfprocessError: boolean = true): Promise { const endpoint = endpoints.courses.invitationLink.replace('{courseId}', courseId); await patch( endpoint, @@ -120,6 +126,8 @@ export function useCourses(): CoursesState { link_duration: linkDuration, }, response, + undefined, + selfprocessError ); } diff --git a/frontend/src/composables/services/docker.service.ts b/frontend/src/composables/services/docker.service.ts index 072be900..48cb2adb 100644 --- a/frontend/src/composables/services/docker.service.ts +++ b/frontend/src/composables/services/docker.service.ts @@ -30,22 +30,22 @@ export function useDockerImages(): DockerImagesState { const dockerImages = ref(null); const response = ref(null); - async function getDockerImages(): Promise { + async function getDockerImages(selfprocessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.index; - await getList(endpoint, dockerImages, DockerImage.fromJSON); + await getList(endpoint, dockerImages, DockerImage.fromJSON, selfprocessError); } - async function searchDockerImages(filters: Filter, page: number, pageSize: number): Promise { + async function searchDockerImages(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.search; - await getPaginatedList(endpoint, filters, page, pageSize, pagination, DockerImage.fromJSON); + await getPaginatedList(endpoint, filters, page, pageSize, pagination, DockerImage.fromJSON, selfprocessError); } - async function patchDockerImage(dockerData: DockerImage): Promise { + async function patchDockerImage(dockerData: DockerImage, selfprocessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.patch.replace('{id}', dockerData.id); - await patch(endpoint, { public: dockerData.public }, response); + await patch(endpoint, { public: dockerData.public }, response, undefined, selfprocessError); } - async function createDockerImage(dockerData: DockerImage, file: File): Promise { + async function createDockerImage(dockerData: DockerImage, file: File, selfprocessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.index; await create( endpoint, @@ -57,18 +57,19 @@ export function useDockerImages(): DockerImagesState { response, Response.fromJSON, 'multipart/form-data', + selfprocessError ); } - async function deleteDockerImage(id: string): Promise { + async function deleteDockerImage(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.retrieve.replace('{id}', id); - await deleteId(endpoint, response, Response.fromJSON); + await deleteId(endpoint, response, Response.fromJSON, selfprocessError); } - async function deleteDockerImages(ids: string[]): Promise { + async function deleteDockerImages(ids: string[], selfprocessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.deleteMany; const data = { ids }; - await deleteIdWithData(endpoint, data, response, Response.fromJSON); + await deleteIdWithData(endpoint, data, response, Response.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/extra_checks.service.ts b/frontend/src/composables/services/extra_checks.service.ts index cca16721..60722d1b 100644 --- a/frontend/src/composables/services/extra_checks.service.ts +++ b/frontend/src/composables/services/extra_checks.service.ts @@ -17,12 +17,12 @@ export function useExtraCheck(): ExtraCheckState { const extraChecks = ref(null); const response = ref(null); - async function getExtraChecksByProject(projectId: string): Promise { + async function getExtraChecksByProject(projectId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.extraChecks.byProject.replace('{projectId}', projectId); - await getList(endpoint, extraChecks, ExtraCheck.fromJSON); + await getList(endpoint, extraChecks, ExtraCheck.fromJSON, selfprocessError); } - async function addExtraCheck(extraCheckData: ExtraCheck, projectId: string): Promise { + async function addExtraCheck(extraCheckData: ExtraCheck, projectId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.extraChecks.byProject.replace('{projectId}', projectId); await create( endpoint, @@ -37,12 +37,13 @@ export function useExtraCheck(): ExtraCheckState { extraCheck, ExtraCheck.fromJSON, 'multipart/form-data', + selfprocessError ); } - async function deleteExtraCheck(extraCheckId: string): Promise { + async function deleteExtraCheck(extraCheckId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.extraChecks.retrieve.replace('{id}', extraCheckId); - await deleteId(endpoint, response, Response.fromJSON); + await deleteId(endpoint, response, Response.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/faculty.service.ts b/frontend/src/composables/services/faculty.service.ts index 00e01f37..63fc4c40 100644 --- a/frontend/src/composables/services/faculty.service.ts +++ b/frontend/src/composables/services/faculty.service.ts @@ -16,24 +16,24 @@ export function useFaculty(): FacultyState { const faculties = ref(null); const faculty = ref(null); - async function getFacultyByID(id: string): Promise { + async function getFacultyByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.faculties.retrieve.replace('{id}', id); - await get(endpoint, faculty, Faculty.fromJSON); + await get(endpoint, faculty, Faculty.fromJSON, selfprocessError); } - async function getFaculties(): Promise { + async function getFaculties(selfprocessError: boolean = true): Promise { const endpoint = endpoints.faculties.index; - await getList(endpoint, faculties, Faculty.fromJSON); + await getList(endpoint, faculties, Faculty.fromJSON, selfprocessError); } - async function createFaculty(facultyData: Faculty): Promise { + async function createFaculty(facultyData: Faculty, selfprocessError: boolean = true): Promise { const endpoint = endpoints.faculties.index; - await create(endpoint, { id: facultyData.id, name: facultyData.name }, faculty, Faculty.fromJSON); + await create(endpoint, { id: facultyData.id, name: facultyData.name }, faculty, Faculty.fromJSON, undefined, selfprocessError); } - async function deleteFaculty(id: string): Promise { + async function deleteFaculty(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.faculties.retrieve.replace('{id}', id); - await deleteId(endpoint, faculty, Faculty.fromJSON); + await deleteId(endpoint, faculty, Faculty.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/group.service.ts b/frontend/src/composables/services/group.service.ts index 50ad2e7a..a8b72595 100644 --- a/frontend/src/composables/services/group.service.ts +++ b/frontend/src/composables/services/group.service.ts @@ -17,22 +17,22 @@ export function useGroup(): GroupState { const groups = ref(null); const group = ref(null); - async function getGroupByID(id: string): Promise { + async function getGroupByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.groups.retrieve.replace('{id}', id); - await get(endpoint, group, Group.fromJSON); + await get(endpoint, group, Group.fromJSON, selfprocessError); } - async function getGroupsByProject(projectId: string): Promise { + async function getGroupsByProject(projectId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.groups.byProject.replace('{projectId}', projectId); - await getList(endpoint, groups, Group.fromJSON); + await getList(endpoint, groups, Group.fromJSON, selfprocessError); } - async function getGroupsByStudent(studentId: string): Promise { + async function getGroupsByStudent(studentId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.groups.byStudent.replace('{studentId}', studentId); - await getList(endpoint, groups, Group.fromJSON); + await getList(endpoint, groups, Group.fromJSON, selfprocessError); } - async function createGroup(groupData: Group, projectId: string): Promise { + async function createGroup(groupData: Group, projectId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.groups.byProject.replace('{projectId}', projectId); await create( endpoint, @@ -42,12 +42,14 @@ export function useGroup(): GroupState { }, group, Group.fromJSON, + undefined, + selfprocessError ); } - async function deleteGroup(id: string): Promise { + async function deleteGroup(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.groups.retrieve.replace('{id}', id); - await deleteId(endpoint, group, Group.fromJSON); + await deleteId(endpoint, group, Group.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index 6f49b924..14d659c2 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -14,14 +14,17 @@ import { type Filter } from '@/types/filter/Filter.ts'; * @param ref * @param fromJson */ -export async function get(endpoint: string, ref: Ref, fromJson: (data: any) => T): Promise { +export async function get(endpoint: string, ref: Ref, fromJson: (data: any) => T, selfprocessError: boolean = true): Promise { try { const response = await client.get(endpoint); ref.value = fromJson(response.data); } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - throw error; // Re-throw the error to the caller + if(selfprocessError){ + processError(error); + console.error(error); // Log the error for debugging + }else{ + throw error; // Re-throw the error to the caller + } } } @@ -39,6 +42,7 @@ export async function create( ref: Ref, fromJson: (data: any) => T, contentType: string = 'application/json', + selfprocessError: boolean = true, ): Promise { try { const response = await client.post(endpoint, data, { @@ -48,9 +52,12 @@ export async function create( }); ref.value = fromJson(response.data); } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - throw error; // Re-throw the error to the caller + if(selfprocessError){ + processError(error); + console.error(error); // Log the error for debugging + }else{ + throw error; // Re-throw the error to the caller + } } } @@ -67,6 +74,7 @@ export async function patch( data: any, ref: Ref, contentType: string = 'application/json', + selfprocessError: boolean = true, ): Promise { try { const response: AxiosResponse = await client.patch(endpoint, data, { @@ -76,9 +84,12 @@ export async function patch( }); ref.value = Response.fromJSON(response.data); } catch (error: any) { - processError(error); - console.error(error); - throw error; + if(selfprocessError){ + processError(error); + console.error(error); // Log the error for debugging + }else{ + throw error; // Re-throw the error to the caller + } } } @@ -89,14 +100,17 @@ export async function patch( * @param ref * @param fromJson */ -export async function deleteId(endpoint: string, ref: Ref, fromJson: (data: any) => T): Promise { +export async function deleteId(endpoint: string, ref: Ref, fromJson: (data: any) => T, selfprocessError: boolean = true): Promise { try { const response = await client.delete(endpoint); ref.value = fromJson(response.data); } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - throw error; // Re-throw the error to the caller + if(selfprocessError){ + processError(error); + console.error(error); // Log the error for debugging + }else{ + throw error; // Re-throw the error to the caller + } } } @@ -113,14 +127,18 @@ export async function deleteIdWithData( data: any, ref: Ref, fromJson: (data: any) => T, + selfprocessError: boolean = true, ): Promise { try { const response = await client.delete(endpoint, { data }); ref.value = fromJson(response.data); } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - throw error; // Re-throw the error to the caller + if(selfprocessError){ + processError(error); + console.error(error); // Log the error for debugging + }else{ + throw error; // Re-throw the error to the caller + } } } @@ -131,15 +149,18 @@ export async function deleteIdWithData( * @param ref * @param fromJson */ -export async function getList(endpoint: string, ref: Ref, fromJson: (data: any) => T): Promise { +export async function getList(endpoint: string, ref: Ref, fromJson: (data: any) => T, selfprocessError: boolean = true): Promise { try { const response = await client.get(endpoint); ref.value = response.data.map((data: T) => fromJson(data)); } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging ref.value = []; // Set the ref to an empty array - throw error; // Re-throw the error to the caller + if(selfprocessError){ + processError(error); + console.error(error); // Log the error for debugging + }else{ + throw error; // Re-throw the error to the caller + } } } @@ -160,6 +181,7 @@ export async function getPaginatedList( pageSize: number, pagination: Ref | null>, fromJson: (data: any) => T, + selfprocessError: boolean = true, ): Promise { try { const response = await client.get(endpoint, { @@ -175,9 +197,6 @@ export async function getPaginatedList( results: response.data.results.map((data: T) => fromJson(data)), }; } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging - pagination.value = { // Set the ref to an empty array ...error.data, @@ -185,7 +204,12 @@ export async function getPaginatedList( results: [], }; - throw error; // Re-throw the error to the caller + if(selfprocessError){ + processError(error); + console.error(error); // Log the error for debugging + }else{ + throw error; // Re-throw the error to the caller + } } } @@ -200,6 +224,7 @@ export async function getListMerged( endpoints: string[], ref: Ref, fromJson: (data: any) => T, + selfprocessError: boolean = true, ): Promise { // Create an array to accumulate all response data const allData: T[] = []; @@ -210,10 +235,13 @@ export async function getListMerged( const responseData: T[] = response.data.map((data: T) => fromJson(data)); allData.push(...responseData); // Merge into the allData array } catch (error: any) { - processError(error); - console.error(error); // Log the error for debugging ref.value = []; // Set the ref to an empty array - throw error; // Re-throw the error to the caller + if(selfprocessError){ + processError(error); + console.error(error); // Log the error for debugging + }else{ + throw error; // Re-throw the error to the caller + } } } diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index f7e8fc79..03a1d2c7 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -24,32 +24,32 @@ export function useProject(): ProjectState { const project = ref(null); const response = ref(null); - async function getProjectByID(id: string): Promise { + async function getProjectByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.projects.retrieve.replace('{id}', id); - await get(endpoint, project, Project.fromJSON); + await get(endpoint, project, Project.fromJSON, selfprocessError); } - async function getProjectsByCourse(courseId: string): Promise { + async function getProjectsByCourse(courseId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.projects.byCourse.replace('{courseId}', courseId); - await getList(endpoint, projects, Project.fromJSON); + await getList(endpoint, projects, Project.fromJSON, selfprocessError); } - async function getProjectsByStudent(studentId: string): Promise { + async function getProjectsByStudent(studentId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.projects.byStudent.replace('{studentId}', studentId); - await getList(endpoint, projects, Project.fromJSON); + await getList(endpoint, projects, Project.fromJSON, selfprocessError); } - async function getProjectsByAssistant(assistantId: string): Promise { + async function getProjectsByAssistant(assistantId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.projects.byAssistant.replace('{assistantId}', assistantId); - await getList(endpoint, projects, Project.fromJSON); + await getList(endpoint, projects, Project.fromJSON, selfprocessError); } - async function getProjectsByTeacher(teacherId: string): Promise { + async function getProjectsByTeacher(teacherId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.projects.byTeacher.replace('{teacherId}', teacherId); - await getList(endpoint, projects, Project.fromJSON); + await getList(endpoint, projects, Project.fromJSON, selfprocessError); } - async function getProjectsByCourseAndDeadline(courseId: string, deadlineDate: Date): Promise { + async function getProjectsByCourseAndDeadline(courseId: string, deadlineDate: Date, selfprocessError: boolean = true): Promise { const endpoint = endpoints.projects.byCourse.replace('{courseId}', courseId); await axios @@ -63,7 +63,7 @@ export function useProject(): ProjectState { return project.deadline.toDateString() === deadlineDate.toDateString(); }); }) - .catch((error) => { + .catch((error) => { // TODO tybo if (axios.isAxiosError(error)) { processError(error); console.log(error.response?.data); @@ -73,7 +73,7 @@ export function useProject(): ProjectState { }); } - async function createProject(projectData: Project, courseId: string, numberOfGroups: number): Promise { + async function createProject(projectData: Project, courseId: string, numberOfGroups: number, selfprocessError: boolean = true): Promise { const endpoint = endpoints.projects.byCourse.replace('{courseId}', courseId); // Initialize an empty object to hold the data to send @@ -96,10 +96,10 @@ export function useProject(): ProjectState { requestData.number_groups = numberOfGroups; } - await create(endpoint, requestData, project, Project.fromJSON, 'multipart/form-data'); + await create(endpoint, requestData, project, Project.fromJSON, 'multipart/form-data', selfprocessError); } - async function updateProject(projectData: Project): Promise { + async function updateProject(projectData: Project, selfprocessError: boolean = true): Promise { const endpoint = endpoints.projects.retrieve.replace('{id}', projectData.id); await patch( endpoint, @@ -118,12 +118,13 @@ export function useProject(): ProjectState { }, response, 'multipart/form-data', + selfprocessError ); } - async function deleteProject(id: string): Promise { + async function deleteProject(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.projects.retrieve.replace('{id}', id); - await deleteId(endpoint, project, Project.fromJSON); + await deleteId(endpoint, project, Project.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index cfc89d90..f9cfe0fb 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -16,17 +16,17 @@ export function useStructureCheck(): StructureCheckState { const structureChecks = ref(null); const structureCheck = ref(null); - async function getStructureCheckByID(id: string): Promise { + async function getStructureCheckByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.retrieve.replace('{id}', id); - await get(endpoint, structureCheck, StructureCheck.fromJSON); + await get(endpoint, structureCheck, StructureCheck.fromJSON, selfprocessError); } - async function getStructureCheckByProject(projectId: string): Promise { + async function getStructureCheckByProject(projectId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); - await getList(endpoint, structureChecks, StructureCheck.fromJSON); + await getList(endpoint, structureChecks, StructureCheck.fromJSON, selfprocessError); } - async function createStructureCheck(structureCheckData: StructureCheck, projectId: string): Promise { + async function createStructureCheck(structureCheckData: StructureCheck, projectId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); await create( endpoint, @@ -35,12 +35,14 @@ export function useStructureCheck(): StructureCheckState { }, structureCheck, StructureCheck.fromJSON, + undefined, + selfprocessError ); } - async function deleteStructureCheck(id: string): Promise { + async function deleteStructureCheck(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.retrieve.replace('{id}', id); - await deleteId(endpoint, structureCheck, StructureCheck.fromJSON); + await deleteId(endpoint, structureCheck, StructureCheck.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/student.service.ts b/frontend/src/composables/services/student.service.ts index c70c67bd..cc456d9a 100644 --- a/frontend/src/composables/services/student.service.ts +++ b/frontend/src/composables/services/student.service.ts @@ -26,47 +26,47 @@ export function useStudents(): StudentsState { const student = ref(null); const response = ref(null); - async function getStudentByID(id: string): Promise { + async function getStudentByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.retrieve.replace('{id}', id); - await get(endpoint, student, Student.fromJSON); + await get(endpoint, student, Student.fromJSON, selfprocessError); } - async function getStudents(): Promise { + async function getStudents(selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.index; - await getList(endpoint, students, Student.fromJSON); + await getList(endpoint, students, Student.fromJSON, selfprocessError); } - async function getStudentsByCourse(courseId: string): Promise { + async function getStudentsByCourse(courseId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); - await getList(endpoint, students, Student.fromJSON); + await getList(endpoint, students, Student.fromJSON, selfprocessError); } - async function getStudentsByGroup(groupId: string): Promise { + async function getStudentsByGroup(groupId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); - await getList(endpoint, students, Student.fromJSON); + await getList(endpoint, students, Student.fromJSON, selfprocessError); } - async function studentJoinCourse(courseId: string, studentId: string): Promise { + async function studentJoinCourse(courseId: string, studentId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); - await create(endpoint, { student: studentId }, response, Response.fromJSON); + await create(endpoint, { student: studentId }, response, Response.fromJSON, undefined, selfprocessError); } - async function studentLeaveCourse(courseId: string, studentId: string): Promise { + async function studentLeaveCourse(courseId: string, studentId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); - await deleteIdWithData(endpoint, { student: studentId }, response, Response.fromJSON); + await deleteIdWithData(endpoint, { student: studentId }, response, Response.fromJSON, selfprocessError); } - async function studentJoinGroup(groupId: string, studentId: string): Promise { + async function studentJoinGroup(groupId: string, studentId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); - await create(endpoint, { student: studentId }, response, Response.fromJSON); + await create(endpoint, { student: studentId }, response, Response.fromJSON, undefined, selfprocessError); } - async function studentLeaveGroup(groupId: string, studentId: string): Promise { + async function studentLeaveGroup(groupId: string, studentId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); - await deleteIdWithData(endpoint, { student: studentId }, response, Response.fromJSON); + await deleteIdWithData(endpoint, { student: studentId }, response, Response.fromJSON, selfprocessError); } - async function createStudent(studentData: Student): Promise { + async function createStudent(studentData: Student, selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.index; await create( @@ -77,12 +77,14 @@ export function useStudents(): StudentsState { }, student, Student.fromJSON, + undefined, + selfprocessError ); } - async function deleteStudent(id: string): Promise { + async function deleteStudent(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.students.retrieve.replace('{id}', id); - await deleteId(endpoint, student, Student.fromJSON); + await deleteId(endpoint, student, Student.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/submission.service.ts b/frontend/src/composables/services/submission.service.ts index 77105615..df3dee2c 100644 --- a/frontend/src/composables/services/submission.service.ts +++ b/frontend/src/composables/services/submission.service.ts @@ -17,34 +17,34 @@ export function useSubmission(): SubmissionState { const submissions = ref(null); const submission = ref(null); - async function getSubmissionByID(id: string): Promise { + async function getSubmissionByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.submissions.retrieve.replace('{id}', id); - await get(endpoint, submission, Submission.fromJSON); + await get(endpoint, submission, Submission.fromJSON, selfprocessError); } - async function getSubmissionByProject(projectId: string): Promise { + async function getSubmissionByProject(projectId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.submissions.byProject.replace('{projectId}', projectId); - await getList(endpoint, submissions, Submission.fromJSON); + await getList(endpoint, submissions, Submission.fromJSON, selfprocessError); } - async function getSubmissionByGroup(groupId: string): Promise { + async function getSubmissionByGroup(groupId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.submissions.byGroup.replace('{groupId}', groupId); - await getList(endpoint, submissions, Submission.fromJSON); + await getList(endpoint, submissions, Submission.fromJSON, selfprocessError); } - async function createSubmission(uploadedFiles: File[], groupId: string): Promise { + async function createSubmission(uploadedFiles: File[], groupId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.submissions.byGroup.replace('{groupId}', groupId); // formData is necessary with multiform data (otherwise files value is changed to files[] by axios) const formData = new FormData(); uploadedFiles.forEach((file: File) => { formData.append('files', file); // Gebruik 'files' in plaats van 'files[]' }); - await create(endpoint, formData, submission, Submission.fromJSONCreate, 'multipart/form-data'); + await create(endpoint, formData, submission, Submission.fromJSONCreate, 'multipart/form-data', selfprocessError); } - async function deleteSubmission(id: string): Promise { + async function deleteSubmission(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.submissions.retrieve.replace('{id}', id); - await deleteId(endpoint, submission, Submission.fromJSON); + await deleteId(endpoint, submission, Submission.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/submission_status.service.ts b/frontend/src/composables/services/submission_status.service.ts index 77174b7a..e7fee07d 100644 --- a/frontend/src/composables/services/submission_status.service.ts +++ b/frontend/src/composables/services/submission_status.service.ts @@ -11,9 +11,9 @@ interface SubmissionStatusState { export function useSubmissionStatus(): SubmissionStatusState { const submissionStatus = ref(null); - async function getSubmissionStatusByProject(projectId: string): Promise { + async function getSubmissionStatusByProject(projectId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.submissions.status.replace('{projectId}', projectId); - await get(endpoint, submissionStatus, SubmissionStatus.fromJSON); + await get(endpoint, submissionStatus, SubmissionStatus.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/teacher.service.ts b/frontend/src/composables/services/teacher.service.ts index 11cf66bc..2d6cf05c 100644 --- a/frontend/src/composables/services/teacher.service.ts +++ b/frontend/src/composables/services/teacher.service.ts @@ -30,37 +30,37 @@ export function useTeacher(): TeacherState { const response = ref(null); const teacherPagination = ref | null>(null); - async function getTeacherByID(id: string): Promise { + async function getTeacherByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.teachers.retrieve.replace('{id}', id); - await get(endpoint, teacher, Teacher.fromJSON); + await get(endpoint, teacher, Teacher.fromJSON, selfprocessError); } - async function getTeachersByCourse(courseId: string): Promise { + async function getTeachersByCourse(courseId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); - await getList(endpoint, teachers, Teacher.fromJSON); + await getList(endpoint, teachers, Teacher.fromJSON, selfprocessError); } - async function getTeachers(): Promise { + async function getTeachers(selfprocessError: boolean = true): Promise { const endpoint = endpoints.teachers.index; - await getList(endpoint, teachers, Teacher.fromJSON); + await getList(endpoint, teachers, Teacher.fromJSON, selfprocessError); } - async function searchTeachers(filters: Filter, page: number, pageSize: number): Promise { + async function searchTeachers(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { const endpoint = endpoints.teachers.search; - await getPaginatedList(endpoint, filters, page, pageSize, teacherPagination, Teacher.fromJSON); + await getPaginatedList(endpoint, filters, page, pageSize, teacherPagination, Teacher.fromJSON, selfprocessError); } - async function teacherJoinCourse(courseId: string, teacherId: string): Promise { + async function teacherJoinCourse(courseId: string, teacherId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); - await create(endpoint, { teacher: teacherId }, response, Response.fromJSON); + await create(endpoint, { teacher: teacherId }, response, Response.fromJSON, undefined, selfprocessError); } - async function teacherLeaveCourse(courseId: string, teacherId: string): Promise { + async function teacherLeaveCourse(courseId: string, teacherId: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); - await deleteIdWithData(endpoint, { teacher: teacherId }, response, Response.fromJSON); + await deleteIdWithData(endpoint, { teacher: teacherId }, response, Response.fromJSON, selfprocessError); } - async function createTeacher(user: User): Promise { + async function createTeacher(user: User, selfprocessError: boolean = true): Promise { const endpoint = endpoints.teachers.index; await create( endpoint, @@ -69,12 +69,14 @@ export function useTeacher(): TeacherState { }, teacher, Teacher.fromJSON, + undefined, + selfprocessError ); } - async function deleteTeacher(id: string): Promise { + async function deleteTeacher(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.teachers.retrieve.replace('{id}', id); - await deleteId(endpoint, teacher, Teacher.fromJSON); + await deleteId(endpoint, teacher, Teacher.fromJSON, selfprocessError); } return { diff --git a/frontend/src/composables/services/users.service.ts b/frontend/src/composables/services/users.service.ts index 50a3279a..96ed9c38 100644 --- a/frontend/src/composables/services/users.service.ts +++ b/frontend/src/composables/services/users.service.ts @@ -23,22 +23,22 @@ export function useUser(): userState { const user = ref(null); const response = ref(null); - async function getUserByID(id: string): Promise { + async function getUserByID(id: string, selfprocessError: boolean = true): Promise { const endpoint = endpoints.users.retrieve.replace('{id}', id); - await get(endpoint, user, User.fromJSON); + await get(endpoint, user, User.fromJSON, selfprocessError); } - async function getUsers(): Promise { + async function getUsers(selfprocessError: boolean = true): Promise { const endpoint = endpoints.users.index; - await getList(endpoint, users, User.fromJSON); + await getList(endpoint, users, User.fromJSON, selfprocessError); } - async function searchUsers(filters: Filter, page: number, pageSize: number): Promise { + async function searchUsers(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { const endpoint = endpoints.users.search; - await getPaginatedList(endpoint, filters, page, pageSize, pagination, User.fromJSON); + await getPaginatedList(endpoint, filters, page, pageSize, pagination, User.fromJSON, selfprocessError); } - async function createUser(userData: User): Promise { + async function createUser(userData: User, selfprocessError: boolean = true): Promise { const endpoint = endpoints.users.index; await create( endpoint, @@ -51,10 +51,12 @@ export function useUser(): userState { }, user, User.fromJSON, + undefined, + selfprocessError ); } - async function toggleAdmin(id: string, isStaff: boolean): Promise { + async function toggleAdmin(id: string, isStaff: boolean, selfprocessError: boolean = true): Promise { const endpoint = endpoints.users.admin.replace('{id}', id); await patch( endpoint, @@ -62,6 +64,8 @@ export function useUser(): userState { is_staff: isStaff, }, response, + undefined, + selfprocessError ); } From 1c5d3cc9de3df83448a8506e65a66b5aa27f874b Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 11:09:04 +0200 Subject: [PATCH 02/17] chore: make services throw errors to caller if requested --- .../src/composables/services/admin.service.ts | 8 ++--- .../composables/services/assistant.service.ts | 16 ++++----- .../composables/services/course.service.ts | 22 ++++++------ .../composables/services/docker.service.ts | 12 +++---- .../services/extra_checks.service.ts | 6 ++-- .../composables/services/faculty.service.ts | 8 ++--- .../src/composables/services/group.service.ts | 10 +++--- .../composables/services/project.service.ts | 34 +++++++++++-------- .../services/structure_check.service.ts | 8 ++--- .../composables/services/student.service.ts | 20 +++++------ .../services/submission.service.ts | 10 +++--- .../services/submission_status.service.ts | 2 +- .../composables/services/teacher.service.ts | 16 ++++----- .../src/composables/services/users.service.ts | 10 +++--- 14 files changed, 93 insertions(+), 89 deletions(-) diff --git a/frontend/src/composables/services/admin.service.ts b/frontend/src/composables/services/admin.service.ts index 485b3bb3..71eec70a 100644 --- a/frontend/src/composables/services/admin.service.ts +++ b/frontend/src/composables/services/admin.service.ts @@ -6,10 +6,10 @@ import { User } from '@/types/users/User.ts'; interface AdminState { admins: Ref; admin: Ref; - getAdminByID: (id: string) => Promise; - getAdmins: () => Promise; - createAdmin: (adminData: User) => Promise; - deleteAdmin: (id: string) => Promise; + getAdminByID: (id: string, selfprocessError?: boolean) => Promise; + getAdmins: (selfprocessError?: boolean) => Promise; + createAdmin: (adminData: User, selfprocessError?: boolean) => Promise; + deleteAdmin: (id: string, selfprocessError?: boolean) => Promise; } export function useAdmin(): AdminState { diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index 7a731beb..0fb3761c 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -12,14 +12,14 @@ interface AssistantState { assistant: Ref; response: Ref; assistantPagination: Ref | null>; - getAssistantByID: (id: string, init?: boolean) => Promise; - getAssistantsByCourse: (courseId: string) => Promise; - getAssistants: () => Promise; - searchAssistants: (filters: Filter, page: number, pageSize: number) => Promise; - assistantJoinCourse: (courseId: string, assistantId: string) => Promise; - assistantLeaveCourse: (courseId: string, assistantId: string) => Promise; - createAssistant: (assistantData: Assistant) => Promise; - deleteAssistant: (id: string) => Promise; + getAssistantByID: (id: string, selfprocessError?: boolean) => Promise; + getAssistantsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; + getAssistants: (selfprocessError?: boolean) => Promise; + searchAssistants: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; + assistantJoinCourse: (courseId: string, assistantId: string, selfprocessError?: boolean) => Promise; + assistantLeaveCourse: (courseId: string, assistantId: string, selfprocessError?: boolean) => Promise; + createAssistant: (assistantData: Assistant, selfprocessError?: boolean) => Promise; + deleteAssistant: (id: string, selfprocessError?: boolean) => Promise; } export function useAssistant(): AssistantState { diff --git a/frontend/src/composables/services/course.service.ts b/frontend/src/composables/services/course.service.ts index 8cd52a87..54fd835a 100644 --- a/frontend/src/composables/services/course.service.ts +++ b/frontend/src/composables/services/course.service.ts @@ -10,17 +10,17 @@ interface CoursesState { pagination: Ref; courses: Ref; course: Ref; - getCourseByID: (id: string) => Promise; - getCourses: () => Promise; - searchCourses: (filters: Filter, page: number, pageSize: number) => Promise; - getCoursesByStudent: (studentId: string) => Promise; - getCoursesByTeacher: (teacherId: string) => Promise; - getCourseByAssistant: (assistantId: string) => Promise; - createCourse: (courseData: Course) => Promise; - updateCourse: (courseData: Course) => Promise; - cloneCourse: (courseId: string, cloneAssistants: boolean, cloneTeachers: boolean) => Promise; - activateInvitationLink: (courseId: string, linkDuration: number) => Promise; - deleteCourse: (id: string) => Promise; + getCourseByID: (id: string, selfprocessError?: boolean) => Promise; + getCourses: (selfprocessError?: boolean) => Promise; + searchCourses: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; + getCoursesByStudent: (studentId: string, selfprocessError?: boolean) => Promise; + getCoursesByTeacher: (teacherId: string, selfprocessError?: boolean) => Promise; + getCourseByAssistant: (assistantId: string, selfprocessError?: boolean) => Promise; + createCourse: (courseData: Course, selfprocessError?: boolean) => Promise; + updateCourse: (courseData: Course, selfprocessError?: boolean) => Promise; + cloneCourse: (courseId: string, cloneAssistants: boolean, cloneTeachers: boolean, selfprocessError?: boolean) => Promise; + activateInvitationLink: (courseId: string, linkDuration: number, selfprocessError?: boolean) => Promise; + deleteCourse: (id: string, selfprocessError?: boolean) => Promise; } export function useCourses(): CoursesState { diff --git a/frontend/src/composables/services/docker.service.ts b/frontend/src/composables/services/docker.service.ts index 48cb2adb..df9bdd31 100644 --- a/frontend/src/composables/services/docker.service.ts +++ b/frontend/src/composables/services/docker.service.ts @@ -17,12 +17,12 @@ interface DockerImagesState { pagination: Ref | null>; dockerImages: Ref; response: Ref; - getDockerImages: () => Promise; - searchDockerImages: (filters: Filter, page: number, pageSize: number) => Promise; - patchDockerImage: (dockerData: DockerImage) => Promise; - createDockerImage: (dockerData: DockerImage, file: File) => Promise; - deleteDockerImage: (id: string) => Promise; - deleteDockerImages: (ids: string[]) => Promise; + getDockerImages: (selfprocessError?: boolean) => Promise; + searchDockerImages: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; + patchDockerImage: (dockerData: DockerImage, selfprocessError?: boolean) => Promise; + createDockerImage: (dockerData: DockerImage, file: File, selfprocessError?: boolean) => Promise; + deleteDockerImage: (id: string, selfprocessError?: boolean) => Promise; + deleteDockerImages: (ids: string[], selfprocessError?: boolean) => Promise; } export function useDockerImages(): DockerImagesState { diff --git a/frontend/src/composables/services/extra_checks.service.ts b/frontend/src/composables/services/extra_checks.service.ts index 60722d1b..8cac1ecd 100644 --- a/frontend/src/composables/services/extra_checks.service.ts +++ b/frontend/src/composables/services/extra_checks.service.ts @@ -7,9 +7,9 @@ import { Response } from '@/types/Response'; interface ExtraCheckState { extraCheck: Ref; extraChecks: Ref; - getExtraChecksByProject: (projectId: string) => Promise; - addExtraCheck: (extraCheckData: ExtraCheck, projectId: string) => Promise; - deleteExtraCheck: (extraCheckId: string) => Promise; + getExtraChecksByProject: (projectId: string, selfprocessError?: boolean) => Promise; + addExtraCheck: (extraCheckData: ExtraCheck, projectId: string, selfprocessError?: boolean) => Promise; + deleteExtraCheck: (extraCheckId: string, selfprocessError?: boolean) => Promise; } export function useExtraCheck(): ExtraCheckState { diff --git a/frontend/src/composables/services/faculty.service.ts b/frontend/src/composables/services/faculty.service.ts index 63fc4c40..23fcb85f 100644 --- a/frontend/src/composables/services/faculty.service.ts +++ b/frontend/src/composables/services/faculty.service.ts @@ -6,10 +6,10 @@ import { get, getList, create, deleteId } from '@/composables/services/helpers.t interface FacultyState { faculties: Ref; faculty: Ref; - getFacultyByID: (id: string) => Promise; - getFaculties: () => Promise; - createFaculty: (facultyData: Faculty) => Promise; - deleteFaculty: (id: string) => Promise; + getFacultyByID: (id: string, selfprocessError?: boolean) => Promise; + getFaculties: (selfprocessError?: boolean) => Promise; + createFaculty: (facultyData: Faculty, selfprocessError?: boolean) => Promise; + deleteFaculty: (id: string, selfprocessError?: boolean) => Promise; } export function useFaculty(): FacultyState { diff --git a/frontend/src/composables/services/group.service.ts b/frontend/src/composables/services/group.service.ts index a8b72595..39d50ba7 100644 --- a/frontend/src/composables/services/group.service.ts +++ b/frontend/src/composables/services/group.service.ts @@ -6,11 +6,11 @@ import { get, getList, create, deleteId } from '@/composables/services/helpers.t interface GroupState { groups: Ref; group: Ref; - getGroupByID: (id: string) => Promise; - getGroupsByProject: (projectId: string) => Promise; - getGroupsByStudent: (studentId: string) => Promise; - createGroup: (groupData: Group, projectId: string) => Promise; - deleteGroup: (id: string) => Promise; + getGroupByID: (id: string, selfprocessError?: boolean) => Promise; + getGroupsByProject: (projectId: string, selfprocessError?: boolean) => Promise; + getGroupsByStudent: (studentId: string, selfprocessError?: boolean) => Promise; + createGroup: (groupData: Group, projectId: string, selfprocessError?: boolean) => Promise; + deleteGroup: (id: string, selfprocessError?: boolean) => Promise; } export function useGroup(): GroupState { diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index 03a1d2c7..aa0c75b7 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -8,15 +8,15 @@ import { type Response } from '@/types/Response.ts'; interface ProjectState { projects: Ref; project: Ref; - getProjectByID: (id: string) => Promise; - getProjectsByCourse: (courseId: string) => Promise; - getProjectsByStudent: (studentId: string) => Promise; - getProjectsByAssistant: (assistantId: string) => Promise; - getProjectsByTeacher: (teacherId: string) => Promise; - getProjectsByCourseAndDeadline: (courseId: string, deadlineDate: Date) => Promise; - createProject: (projectData: Project, courseId: string, numberOfGroups: number) => Promise; - updateProject: (projectData: Project) => Promise; - deleteProject: (id: string) => Promise; + getProjectByID: (id: string, selfprocessError?: boolean) => Promise; + getProjectsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; + getProjectsByStudent: (studentId: string, selfprocessError?: boolean) => Promise; + getProjectsByAssistant: (assistantId: string, selfprocessError?: boolean) => Promise; + getProjectsByTeacher: (teacherId: string, selfprocessError?: boolean) => Promise; + getProjectsByCourseAndDeadline: (courseId: string, deadlineDate: Date, selfprocessError?: boolean) => Promise; + createProject: (projectData: Project, courseId: string, numberOfGroups: number, selfprocessError?: boolean) => Promise; + updateProject: (projectData: Project, selfprocessError?: boolean) => Promise; + deleteProject: (id: string, selfprocessError?: boolean) => Promise; } export function useProject(): ProjectState { @@ -63,12 +63,16 @@ export function useProject(): ProjectState { return project.deadline.toDateString() === deadlineDate.toDateString(); }); }) - .catch((error) => { // TODO tybo - if (axios.isAxiosError(error)) { - processError(error); - console.log(error.response?.data); - } else { - console.error('An unexpected error ocurred: ', error); + .catch((error) => { + if(selfprocessError){ + if (axios.isAxiosError(error)) { + processError(error); + console.log(error.response?.data); + } else { + console.error('An unexpected error ocurred: ', error); + } + }else{ + throw error; // Re-throw the error to the caller } }); } diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index f9cfe0fb..7bdac161 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -6,10 +6,10 @@ import { get, getList, create, deleteId } from '@/composables/services/helpers.t interface StructureCheckState { structureChecks: Ref; structureCheck: Ref; - getStructureCheckByID: (id: string) => Promise; - getStructureCheckByProject: (projectId: string) => Promise; - createStructureCheck: (structureCheckData: StructureCheck, projectId: string) => Promise; - deleteStructureCheck: (id: string) => Promise; + getStructureCheckByID: (id: string, selfprocessError?: boolean) => Promise; + getStructureCheckByProject: (projectId: string, selfprocessError?: boolean) => Promise; + createStructureCheck: (structureCheckData: StructureCheck, projectId: string, selfprocessError?: boolean) => Promise; + deleteStructureCheck: (id: string, selfprocessError?: boolean) => Promise; } export function useStructureCheck(): StructureCheckState { diff --git a/frontend/src/composables/services/student.service.ts b/frontend/src/composables/services/student.service.ts index cc456d9a..edb8b8f0 100644 --- a/frontend/src/composables/services/student.service.ts +++ b/frontend/src/composables/services/student.service.ts @@ -8,16 +8,16 @@ interface StudentsState { students: Ref; student: Ref; response: Ref; - getStudentByID: (id: string, init?: boolean) => Promise; - getStudents: () => Promise; - getStudentsByCourse: (courseId: string) => Promise; - getStudentsByGroup: (groupId: string) => Promise; - createStudent: (studentData: Student) => Promise; - deleteStudent: (id: string) => Promise; - studentJoinCourse: (courseId: string, studentId: string) => Promise; - studentLeaveCourse: (courseId: string, studentId: string) => Promise; - studentJoinGroup: (groupId: string, studentId: string) => Promise; - studentLeaveGroup: (groupId: string, studentId: string) => Promise; + getStudentByID: (id: string, selfprocessError?: boolean) => Promise; + getStudents: (selfprocessError?: boolean) => Promise; + getStudentsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; + getStudentsByGroup: (groupId: string, selfprocessError?: boolean) => Promise; + createStudent: (studentData: Student, selfprocessError?: boolean) => Promise; + deleteStudent: (id: string, selfprocessError?: boolean) => Promise; + studentJoinCourse: (courseId: string, studentId: string, selfprocessError?: boolean) => Promise; + studentLeaveCourse: (courseId: string, studentId: string, selfprocessError?: boolean) => Promise; + studentJoinGroup: (groupId: string, studentId: string, selfprocessError?: boolean) => Promise; + studentLeaveGroup: (groupId: string, studentId: string, selfprocessError?: boolean) => Promise; } export function useStudents(): StudentsState { diff --git a/frontend/src/composables/services/submission.service.ts b/frontend/src/composables/services/submission.service.ts index df3dee2c..25383bf5 100644 --- a/frontend/src/composables/services/submission.service.ts +++ b/frontend/src/composables/services/submission.service.ts @@ -6,11 +6,11 @@ import { get, getList, deleteId, create } from '@/composables/services/helpers.t interface SubmissionState { submissions: Ref; submission: Ref; - getSubmissionByID: (id: string) => Promise; - getSubmissionByProject: (projectId: string) => Promise; - getSubmissionByGroup: (groupId: string) => Promise; - createSubmission: (submissionData: UnwrapRef, groupId: string) => Promise; - deleteSubmission: (id: string) => Promise; + getSubmissionByID: (id: string, selfprocessError?: boolean) => Promise; + getSubmissionByProject: (projectId: string, selfprocessError?: boolean) => Promise; + getSubmissionByGroup: (groupId: string, selfprocessError?: boolean) => Promise; + createSubmission: (submissionData: UnwrapRef, groupId: string, selfprocessError?: boolean) => Promise; + deleteSubmission: (id: string, selfprocessError?: boolean) => Promise; } export function useSubmission(): SubmissionState { diff --git a/frontend/src/composables/services/submission_status.service.ts b/frontend/src/composables/services/submission_status.service.ts index e7fee07d..5e9e2e84 100644 --- a/frontend/src/composables/services/submission_status.service.ts +++ b/frontend/src/composables/services/submission_status.service.ts @@ -5,7 +5,7 @@ import { SubmissionStatus } from '@/types/SubmisionStatus'; interface SubmissionStatusState { submissionStatus: Ref; - getSubmissionStatusByProject: (projectId: string) => Promise; + getSubmissionStatusByProject: (projectId: string, selfprocessError?: boolean) => Promise; } export function useSubmissionStatus(): SubmissionStatusState { diff --git a/frontend/src/composables/services/teacher.service.ts b/frontend/src/composables/services/teacher.service.ts index 2d6cf05c..15dbd256 100644 --- a/frontend/src/composables/services/teacher.service.ts +++ b/frontend/src/composables/services/teacher.service.ts @@ -13,14 +13,14 @@ interface TeacherState { teacher: Ref; response: Ref; teacherPagination: Ref | null>; - getTeacherByID: (id: string, init?: boolean) => Promise; - getTeachersByCourse: (courseId: string) => Promise; - getTeachers: () => Promise; - searchTeachers: (filters: Filter, page: number, pageSize: number) => Promise; - teacherJoinCourse: (courseId: string, teacherId: string) => Promise; - teacherLeaveCourse: (courseId: string, teacherId: string) => Promise; - createTeacher: (teacherData: Teacher) => Promise; - deleteTeacher: (id: string) => Promise; + getTeacherByID: (id: string, selfprocessError?: boolean) => Promise; + getTeachersByCourse: (courseId: string, selfprocessError?: boolean) => Promise; + getTeachers: (selfprocessError?: boolean) => Promise; + searchTeachers: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; + teacherJoinCourse: (courseId: string, teacherId: string, selfprocessError?: boolean) => Promise; + teacherLeaveCourse: (courseId: string, teacherId: string, selfprocessError?: boolean) => Promise; + createTeacher: (teacherData: Teacher, selfprocessError?: boolean) => Promise; + deleteTeacher: (id: string, selfprocessError?: boolean) => Promise; } export function useTeacher(): TeacherState { diff --git a/frontend/src/composables/services/users.service.ts b/frontend/src/composables/services/users.service.ts index 96ed9c38..41edbac5 100644 --- a/frontend/src/composables/services/users.service.ts +++ b/frontend/src/composables/services/users.service.ts @@ -10,11 +10,11 @@ interface userState { pagination: Ref | null>; users: Ref; user: Ref; - getUserByID: (id: string) => Promise; - getUsers: () => Promise; - searchUsers: (filters: Filter, page: number, pageSize: number) => Promise; - createUser: (user_data: User) => Promise; - toggleAdmin: (id: string, is_staff: boolean) => Promise; + getUserByID: (id: string, selfprocessError?: boolean) => Promise; + getUsers: (selfprocessError?: boolean) => Promise; + searchUsers: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; + createUser: (user_data: User, selfprocessError?: boolean) => Promise; + toggleAdmin: (id: string, is_staff: boolean, selfprocessError?: boolean) => Promise; } export function useUser(): userState { From 194938ed454ab6ea351b8bebbbc0b60267397685 Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 11:17:07 +0200 Subject: [PATCH 03/17] chore: place init?:boolean back --- frontend/src/composables/services/assistant.service.ts | 2 +- frontend/src/composables/services/student.service.ts | 2 +- frontend/src/composables/services/teacher.service.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index 0fb3761c..dfb03185 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -12,7 +12,7 @@ interface AssistantState { assistant: Ref; response: Ref; assistantPagination: Ref | null>; - getAssistantByID: (id: string, selfprocessError?: boolean) => Promise; + getAssistantByID: (id: string, init?:boolean, selfprocessError?: boolean) => Promise; getAssistantsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; getAssistants: (selfprocessError?: boolean) => Promise; searchAssistants: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; diff --git a/frontend/src/composables/services/student.service.ts b/frontend/src/composables/services/student.service.ts index edb8b8f0..efde10c4 100644 --- a/frontend/src/composables/services/student.service.ts +++ b/frontend/src/composables/services/student.service.ts @@ -8,7 +8,7 @@ interface StudentsState { students: Ref; student: Ref; response: Ref; - getStudentByID: (id: string, selfprocessError?: boolean) => Promise; + getStudentByID: (id: string, init?:boolean, selfprocessError?: boolean) => Promise; getStudents: (selfprocessError?: boolean) => Promise; getStudentsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; getStudentsByGroup: (groupId: string, selfprocessError?: boolean) => Promise; diff --git a/frontend/src/composables/services/teacher.service.ts b/frontend/src/composables/services/teacher.service.ts index 15dbd256..5c3f6859 100644 --- a/frontend/src/composables/services/teacher.service.ts +++ b/frontend/src/composables/services/teacher.service.ts @@ -13,7 +13,7 @@ interface TeacherState { teacher: Ref; response: Ref; teacherPagination: Ref | null>; - getTeacherByID: (id: string, selfprocessError?: boolean) => Promise; + getTeacherByID: (id: string, init?:boolean, selfprocessError?: boolean) => Promise; getTeachersByCourse: (courseId: string, selfprocessError?: boolean) => Promise; getTeachers: (selfprocessError?: boolean) => Promise; searchTeachers: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; From a597d1eecf2e695acb07556d049f457186e72cfe Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 11:40:10 +0200 Subject: [PATCH 04/17] chore: rewrite landers code --- .../composables/services/project.service.ts | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index aa0c75b7..5f0a2cb4 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -50,31 +50,11 @@ export function useProject(): ProjectState { } async function getProjectsByCourseAndDeadline(courseId: string, deadlineDate: Date, selfprocessError: boolean = true): Promise { - const endpoint = endpoints.projects.byCourse.replace('{courseId}', courseId); - - await axios - .get(endpoint) - .then((response) => { - const allProjects = response.data.map((projectData: Project) => Project.fromJSON(projectData)); - - // Filter projects based on the deadline date - // Update the projects ref with the filtered projects - projects.value = allProjects.filter((project: Project) => { - return project.deadline.toDateString() === deadlineDate.toDateString(); - }); - }) - .catch((error) => { - if(selfprocessError){ - if (axios.isAxiosError(error)) { - processError(error); - console.log(error.response?.data); - } else { - console.error('An unexpected error ocurred: ', error); - } - }else{ - throw error; // Re-throw the error to the caller - } - }); + await getProjectsByCourse(courseId, selfprocessError); + const allProjects = (projects.value || []).map((projectData: any) => Project.fromJSON(projectData)); + projects.value = allProjects.filter((project: Project) => { + return project.deadline.toDateString() === deadlineDate.toDateString(); + }); } async function createProject(projectData: Project, courseId: string, numberOfGroups: number, selfprocessError: boolean = true): Promise { From b4dd6535a95cc4cf41159d635ee3305f02506499 Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 11:49:20 +0200 Subject: [PATCH 05/17] chore: fix linter --- .../src/composables/services/admin.service.ts | 2 +- .../composables/services/assistant.service.ts | 48 ++++++++++++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/frontend/src/composables/services/admin.service.ts b/frontend/src/composables/services/admin.service.ts index 71eec70a..b22d1608 100644 --- a/frontend/src/composables/services/admin.service.ts +++ b/frontend/src/composables/services/admin.service.ts @@ -36,7 +36,7 @@ export function useAdmin(): AdminState { admin, User.fromJSON, undefined, - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index dfb03185..7bd9e815 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -12,7 +12,7 @@ interface AssistantState { assistant: Ref; response: Ref; assistantPagination: Ref | null>; - getAssistantByID: (id: string, init?:boolean, selfprocessError?: boolean) => Promise; + getAssistantByID: (id: string, init?: boolean, selfprocessError?: boolean) => Promise; getAssistantsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; getAssistants: (selfprocessError?: boolean) => Promise; searchAssistants: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; @@ -44,19 +44,53 @@ export function useAssistant(): AssistantState { await getList(endpoint, assistants, Assistant.fromJSON, selfprocessError); } - async function searchAssistants(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { + async function searchAssistants( + filters: Filter, + page: number, + pageSize: number, + selfprocessError: boolean = true + ): Promise { const endpoint = endpoints.assistants.search; - await getPaginatedList(endpoint, filters, page, pageSize, assistantPagination, Assistant.fromJSON, selfprocessError); + await getPaginatedList( + endpoint, + filters, + page, + pageSize, + assistantPagination, + Assistant.fromJSON, + selfprocessError + ); } - async function assistantJoinCourse(courseId: string, assistantId: string, selfprocessError: boolean = true): Promise { + async function assistantJoinCourse( + courseId: string, + assistantId: string, + selfprocessError: boolean = true + ): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); - await create(endpoint, { assistant: assistantId }, response, Response.fromJSON, undefined, selfprocessError); + await create( + endpoint, + { assistant: assistantId }, + response, + Response.fromJSON, + undefined, + selfprocessError + ); } - async function assistantLeaveCourse(courseId: string, assistantId: string, selfprocessError: boolean = true): Promise { + async function assistantLeaveCourse( + courseId: string, + assistantId: string, + selfprocessError: boolean = true + ): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); - await deleteIdWithData(endpoint, { assistant: assistantId }, response, Response.fromJSON, selfprocessError); + await deleteIdWithData( + endpoint, + { assistant: assistantId }, + response, + Response.fromJSON, + selfprocessError + ); } async function createAssistant(user: User, selfprocessError: boolean = true): Promise { From 94ff39050bbd49063b2f1f8109ffac16bac8183d Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 11:55:57 +0200 Subject: [PATCH 06/17] chore: fix linter --- .../composables/services/student.service.ts | 2 +- .../composables/services/teacher.service.ts | 50 ++++++++++++++++--- .../src/composables/services/users.service.ts | 11 ++-- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/frontend/src/composables/services/student.service.ts b/frontend/src/composables/services/student.service.ts index efde10c4..7f079f45 100644 --- a/frontend/src/composables/services/student.service.ts +++ b/frontend/src/composables/services/student.service.ts @@ -8,7 +8,7 @@ interface StudentsState { students: Ref; student: Ref; response: Ref; - getStudentByID: (id: string, init?:boolean, selfprocessError?: boolean) => Promise; + getStudentByID: (id: string, init?: boolean, selfprocessError?: boolean) => Promise; getStudents: (selfprocessError?: boolean) => Promise; getStudentsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; getStudentsByGroup: (groupId: string, selfprocessError?: boolean) => Promise; diff --git a/frontend/src/composables/services/teacher.service.ts b/frontend/src/composables/services/teacher.service.ts index 5c3f6859..791490ef 100644 --- a/frontend/src/composables/services/teacher.service.ts +++ b/frontend/src/composables/services/teacher.service.ts @@ -13,7 +13,7 @@ interface TeacherState { teacher: Ref; response: Ref; teacherPagination: Ref | null>; - getTeacherByID: (id: string, init?:boolean, selfprocessError?: boolean) => Promise; + getTeacherByID: (id: string, init?: boolean, selfprocessError?: boolean) => Promise; getTeachersByCourse: (courseId: string, selfprocessError?: boolean) => Promise; getTeachers: (selfprocessError?: boolean) => Promise; searchTeachers: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; @@ -45,19 +45,53 @@ export function useTeacher(): TeacherState { await getList(endpoint, teachers, Teacher.fromJSON, selfprocessError); } - async function searchTeachers(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { + async function searchTeachers( + filters: Filter, + page: number, + pageSize: number, + selfprocessError: boolean = true + ): Promise { const endpoint = endpoints.teachers.search; - await getPaginatedList(endpoint, filters, page, pageSize, teacherPagination, Teacher.fromJSON, selfprocessError); + await getPaginatedList( + endpoint, + filters, + page, + pageSize, + teacherPagination, + Teacher.fromJSON, + selfprocessError + ); } - async function teacherJoinCourse(courseId: string, teacherId: string, selfprocessError: boolean = true): Promise { + async function teacherJoinCourse( + courseId: string, + teacherId: string, + selfprocessError: boolean = true + ): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); - await create(endpoint, { teacher: teacherId }, response, Response.fromJSON, undefined, selfprocessError); + await create( + endpoint, + { teacher: teacherId }, + response, + Response.fromJSON, + undefined, + selfprocessError + ); } - async function teacherLeaveCourse(courseId: string, teacherId: string, selfprocessError: boolean = true): Promise { + async function teacherLeaveCourse( + courseId: string, + teacherId: string, + selfprocessError: boolean = true + ): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); - await deleteIdWithData(endpoint, { teacher: teacherId }, response, Response.fromJSON, selfprocessError); + await deleteIdWithData( + endpoint, + { teacher: teacherId }, + response, + Response.fromJSON, + selfprocessError, + ); } async function createTeacher(user: User, selfprocessError: boolean = true): Promise { @@ -70,7 +104,7 @@ export function useTeacher(): TeacherState { teacher, Teacher.fromJSON, undefined, - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/users.service.ts b/frontend/src/composables/services/users.service.ts index 41edbac5..93f2af5a 100644 --- a/frontend/src/composables/services/users.service.ts +++ b/frontend/src/composables/services/users.service.ts @@ -33,7 +33,12 @@ export function useUser(): userState { await getList(endpoint, users, User.fromJSON, selfprocessError); } - async function searchUsers(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { + async function searchUsers( + filters: Filter, + page: number, + pageSize: number, + selfprocessError: boolean = true + ): Promise { const endpoint = endpoints.users.search; await getPaginatedList(endpoint, filters, page, pageSize, pagination, User.fromJSON, selfprocessError); } @@ -52,7 +57,7 @@ export function useUser(): userState { user, User.fromJSON, undefined, - selfprocessError + selfprocessError, ); } @@ -65,7 +70,7 @@ export function useUser(): userState { }, response, undefined, - selfprocessError + selfprocessError, ); } From d48691d8a526cfd3a872b6fea9b449eddc3ce213 Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 12:07:11 +0200 Subject: [PATCH 07/17] chore: fix linter --- .../composables/services/project.service.ts | 36 ++++++++--- .../services/structure_check.service.ts | 14 ++++- .../composables/services/student.service.ts | 60 ++++++++++++++++--- .../services/submission.service.ts | 15 ++++- .../composables/services/teacher.service.ts | 10 ++-- .../src/composables/services/users.service.ts | 2 +- 6 files changed, 109 insertions(+), 28 deletions(-) diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index 5f0a2cb4..63150293 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -1,8 +1,7 @@ import { Project } from '@/types/Project'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import axios from 'axios'; -import { create, deleteId, get, getList, patch, processError } from '@/composables/services/helpers.ts'; +import { create, deleteId, get, getList, patch} from '@/composables/services/helpers.ts'; import { type Response } from '@/types/Response.ts'; interface ProjectState { @@ -14,7 +13,12 @@ interface ProjectState { getProjectsByAssistant: (assistantId: string, selfprocessError?: boolean) => Promise; getProjectsByTeacher: (teacherId: string, selfprocessError?: boolean) => Promise; getProjectsByCourseAndDeadline: (courseId: string, deadlineDate: Date, selfprocessError?: boolean) => Promise; - createProject: (projectData: Project, courseId: string, numberOfGroups: number, selfprocessError?: boolean) => Promise; + createProject: ( + projectData: Project, + courseId: string, + numberOfGroups: number, + selfprocessError?: boolean, + ) => Promise; updateProject: (projectData: Project, selfprocessError?: boolean) => Promise; deleteProject: (id: string, selfprocessError?: boolean) => Promise; } @@ -49,15 +53,24 @@ export function useProject(): ProjectState { await getList(endpoint, projects, Project.fromJSON, selfprocessError); } - async function getProjectsByCourseAndDeadline(courseId: string, deadlineDate: Date, selfprocessError: boolean = true): Promise { + async function getProjectsByCourseAndDeadline( + courseId: string, + deadlineDate: Date, + selfprocessError: boolean = true, + ): Promise { await getProjectsByCourse(courseId, selfprocessError); - const allProjects = (projects.value || []).map((projectData: any) => Project.fromJSON(projectData)); + const allProjects = (projects.value ?? []).map((projectData: Project) => Project.fromJSON(projectData)); projects.value = allProjects.filter((project: Project) => { return project.deadline.toDateString() === deadlineDate.toDateString(); }); } - async function createProject(projectData: Project, courseId: string, numberOfGroups: number, selfprocessError: boolean = true): Promise { + async function createProject( + projectData: Project, + courseId: string, + numberOfGroups: number, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.projects.byCourse.replace('{courseId}', courseId); // Initialize an empty object to hold the data to send @@ -80,7 +93,14 @@ export function useProject(): ProjectState { requestData.number_groups = numberOfGroups; } - await create(endpoint, requestData, project, Project.fromJSON, 'multipart/form-data', selfprocessError); + await create( + endpoint, + requestData, + project, + Project.fromJSON, + 'multipart/form-data', + selfprocessError, + ); } async function updateProject(projectData: Project, selfprocessError: boolean = true): Promise { @@ -102,7 +122,7 @@ export function useProject(): ProjectState { }, response, 'multipart/form-data', - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index 7bdac161..de153bb9 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -8,7 +8,11 @@ interface StructureCheckState { structureCheck: Ref; getStructureCheckByID: (id: string, selfprocessError?: boolean) => Promise; getStructureCheckByProject: (projectId: string, selfprocessError?: boolean) => Promise; - createStructureCheck: (structureCheckData: StructureCheck, projectId: string, selfprocessError?: boolean) => Promise; + createStructureCheck: ( + structureCheckData: StructureCheck, + projectId: string, + selfprocessError?: boolean, + ) => Promise; deleteStructureCheck: (id: string, selfprocessError?: boolean) => Promise; } @@ -26,7 +30,11 @@ export function useStructureCheck(): StructureCheckState { await getList(endpoint, structureChecks, StructureCheck.fromJSON, selfprocessError); } - async function createStructureCheck(structureCheckData: StructureCheck, projectId: string, selfprocessError: boolean = true): Promise { + async function createStructureCheck( + structureCheckData: StructureCheck, + projectId: string, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); await create( endpoint, @@ -36,7 +44,7 @@ export function useStructureCheck(): StructureCheckState { structureCheck, StructureCheck.fromJSON, undefined, - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/student.service.ts b/frontend/src/composables/services/student.service.ts index 7f079f45..70f3f6e2 100644 --- a/frontend/src/composables/services/student.service.ts +++ b/frontend/src/composables/services/student.service.ts @@ -46,24 +46,66 @@ export function useStudents(): StudentsState { await getList(endpoint, students, Student.fromJSON, selfprocessError); } - async function studentJoinCourse(courseId: string, studentId: string, selfprocessError: boolean = true): Promise { + async function studentJoinCourse( + courseId: string, + studentId: string, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); - await create(endpoint, { student: studentId }, response, Response.fromJSON, undefined, selfprocessError); + await create( + endpoint, + { student: studentId }, + response, + Response.fromJSON, + undefined, + selfprocessError, + ); } - async function studentLeaveCourse(courseId: string, studentId: string, selfprocessError: boolean = true): Promise { + async function studentLeaveCourse( + courseId: string, + studentId: string, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); - await deleteIdWithData(endpoint, { student: studentId }, response, Response.fromJSON, selfprocessError); + await deleteIdWithData( + endpoint, + { student: studentId }, + response, + Response.fromJSON, + selfprocessError, + ); } - async function studentJoinGroup(groupId: string, studentId: string, selfprocessError: boolean = true): Promise { + async function studentJoinGroup( + groupId: string, + studentId: string, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); - await create(endpoint, { student: studentId }, response, Response.fromJSON, undefined, selfprocessError); + await create( + endpoint, + { student: studentId }, + response, + Response.fromJSON, + undefined, + selfprocessError, + ); } - async function studentLeaveGroup(groupId: string, studentId: string, selfprocessError: boolean = true): Promise { + async function studentLeaveGroup( + groupId: string, + studentId: string, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); - await deleteIdWithData(endpoint, { student: studentId }, response, Response.fromJSON, selfprocessError); + await deleteIdWithData( + endpoint, + { student: studentId }, + response, + Response.fromJSON, + selfprocessError, + ); } async function createStudent(studentData: Student, selfprocessError: boolean = true): Promise { @@ -78,7 +120,7 @@ export function useStudents(): StudentsState { student, Student.fromJSON, undefined, - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/submission.service.ts b/frontend/src/composables/services/submission.service.ts index 25383bf5..3a888f58 100644 --- a/frontend/src/composables/services/submission.service.ts +++ b/frontend/src/composables/services/submission.service.ts @@ -32,14 +32,25 @@ export function useSubmission(): SubmissionState { await getList(endpoint, submissions, Submission.fromJSON, selfprocessError); } - async function createSubmission(uploadedFiles: File[], groupId: string, selfprocessError: boolean = true): Promise { + async function createSubmission( + uploadedFiles: File[], + groupId: string, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.submissions.byGroup.replace('{groupId}', groupId); // formData is necessary with multiform data (otherwise files value is changed to files[] by axios) const formData = new FormData(); uploadedFiles.forEach((file: File) => { formData.append('files', file); // Gebruik 'files' in plaats van 'files[]' }); - await create(endpoint, formData, submission, Submission.fromJSONCreate, 'multipart/form-data', selfprocessError); + await create( + endpoint, + formData, + submission, + Submission.fromJSONCreate, + 'multipart/form-data', + selfprocessError, + ); } async function deleteSubmission(id: string, selfprocessError: boolean = true): Promise { diff --git a/frontend/src/composables/services/teacher.service.ts b/frontend/src/composables/services/teacher.service.ts index 791490ef..473d71fd 100644 --- a/frontend/src/composables/services/teacher.service.ts +++ b/frontend/src/composables/services/teacher.service.ts @@ -49,7 +49,7 @@ export function useTeacher(): TeacherState { filters: Filter, page: number, pageSize: number, - selfprocessError: boolean = true + selfprocessError: boolean = true, ): Promise { const endpoint = endpoints.teachers.search; await getPaginatedList( @@ -59,14 +59,14 @@ export function useTeacher(): TeacherState { pageSize, teacherPagination, Teacher.fromJSON, - selfprocessError + selfprocessError, ); } async function teacherJoinCourse( courseId: string, teacherId: string, - selfprocessError: boolean = true + selfprocessError: boolean = true, ): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); await create( @@ -75,14 +75,14 @@ export function useTeacher(): TeacherState { response, Response.fromJSON, undefined, - selfprocessError + selfprocessError, ); } async function teacherLeaveCourse( courseId: string, teacherId: string, - selfprocessError: boolean = true + selfprocessError: boolean = true, ): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); await deleteIdWithData( diff --git a/frontend/src/composables/services/users.service.ts b/frontend/src/composables/services/users.service.ts index 93f2af5a..a590b617 100644 --- a/frontend/src/composables/services/users.service.ts +++ b/frontend/src/composables/services/users.service.ts @@ -37,7 +37,7 @@ export function useUser(): userState { filters: Filter, page: number, pageSize: number, - selfprocessError: boolean = true + selfprocessError: boolean = true, ): Promise { const endpoint = endpoints.users.search; await getPaginatedList(endpoint, filters, page, pageSize, pagination, User.fromJSON, selfprocessError); From fb1517b598f919cce6e79871bc521327c4fe961c Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 12:16:05 +0200 Subject: [PATCH 08/17] chore: fix linter --- .../composables/services/assistant.service.ts | 14 ++--- .../composables/services/course.service.ts | 45 ++++++++++++---- .../composables/services/docker.service.ts | 25 +++++++-- .../services/extra_checks.service.ts | 8 ++- .../composables/services/faculty.service.ts | 9 +++- .../src/composables/services/group.service.ts | 2 +- frontend/src/composables/services/helpers.ts | 51 ++++++++++++------- .../composables/services/project.service.ts | 2 +- 8 files changed, 113 insertions(+), 43 deletions(-) diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index 7bd9e815..a6f73176 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -48,7 +48,7 @@ export function useAssistant(): AssistantState { filters: Filter, page: number, pageSize: number, - selfprocessError: boolean = true + selfprocessError: boolean = true, ): Promise { const endpoint = endpoints.assistants.search; await getPaginatedList( @@ -58,14 +58,14 @@ export function useAssistant(): AssistantState { pageSize, assistantPagination, Assistant.fromJSON, - selfprocessError + selfprocessError, ); } async function assistantJoinCourse( courseId: string, assistantId: string, - selfprocessError: boolean = true + selfprocessError: boolean = true, ): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); await create( @@ -74,14 +74,14 @@ export function useAssistant(): AssistantState { response, Response.fromJSON, undefined, - selfprocessError + selfprocessError, ); } async function assistantLeaveCourse( courseId: string, assistantId: string, - selfprocessError: boolean = true + selfprocessError: boolean = true, ): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); await deleteIdWithData( @@ -89,7 +89,7 @@ export function useAssistant(): AssistantState { { assistant: assistantId }, response, Response.fromJSON, - selfprocessError + selfprocessError, ); } @@ -103,7 +103,7 @@ export function useAssistant(): AssistantState { assistant, Assistant.fromJSON, undefined, - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/course.service.ts b/frontend/src/composables/services/course.service.ts index 54fd835a..30e07c45 100644 --- a/frontend/src/composables/services/course.service.ts +++ b/frontend/src/composables/services/course.service.ts @@ -18,7 +18,12 @@ interface CoursesState { getCourseByAssistant: (assistantId: string, selfprocessError?: boolean) => Promise; createCourse: (courseData: Course, selfprocessError?: boolean) => Promise; updateCourse: (courseData: Course, selfprocessError?: boolean) => Promise; - cloneCourse: (courseId: string, cloneAssistants: boolean, cloneTeachers: boolean, selfprocessError?: boolean) => Promise; + cloneCourse: ( + courseId: string, + cloneAssistants: boolean, + cloneTeachers: boolean, + selfprocessError?: boolean, + ) => Promise; activateInvitationLink: (courseId: string, linkDuration: number, selfprocessError?: boolean) => Promise; deleteCourse: (id: string, selfprocessError?: boolean) => Promise; } @@ -39,9 +44,22 @@ export function useCourses(): CoursesState { await getList(endpoint, courses, Course.fromJSON, selfprocessError); } - async function searchCourses(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { + async function searchCourses( + filters: Filter, + page: number, + pageSize: number, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.courses.search; - await getPaginatedList(endpoint, filters, page, pageSize, pagination, Course.fromJSON, selfprocessError); + await getPaginatedList( + endpoint, + filters, + page, + pageSize, + pagination, + Course.fromJSON, + selfprocessError, + ); } async function getCoursesByStudent(studentId: string, selfprocessError: boolean = true): Promise { @@ -75,7 +93,7 @@ export function useCourses(): CoursesState { course, Course.fromJSON, undefined, - selfprocessError + selfprocessError, ); } @@ -94,11 +112,16 @@ export function useCourses(): CoursesState { }, response, undefined, - selfprocessError + selfprocessError, ); } - async function cloneCourse(courseId: string, cloneAssistants: boolean, cloneTeachers: boolean, selfprocessError: boolean = true): Promise { + async function cloneCourse( + courseId: string, + cloneAssistants: boolean, + cloneTeachers: boolean, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.courses.clone.replace('{courseId}', courseId); await create( endpoint, @@ -109,7 +132,7 @@ export function useCourses(): CoursesState { course, Course.fromJSON, undefined, - selfprocessError + selfprocessError, ); } @@ -118,7 +141,11 @@ export function useCourses(): CoursesState { await deleteId(endpoint, course, Course.fromJSON, selfprocessError); } - async function activateInvitationLink(courseId: string, linkDuration: number, selfprocessError: boolean = true): Promise { + async function activateInvitationLink( + courseId: string, + linkDuration: number, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.courses.invitationLink.replace('{courseId}', courseId); await patch( endpoint, @@ -127,7 +154,7 @@ export function useCourses(): CoursesState { }, response, undefined, - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/docker.service.ts b/frontend/src/composables/services/docker.service.ts index df9bdd31..708a8a5b 100644 --- a/frontend/src/composables/services/docker.service.ts +++ b/frontend/src/composables/services/docker.service.ts @@ -35,9 +35,22 @@ export function useDockerImages(): DockerImagesState { await getList(endpoint, dockerImages, DockerImage.fromJSON, selfprocessError); } - async function searchDockerImages(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise { + async function searchDockerImages( + filters: Filter, + page: number, + pageSize: number, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.dockerImages.search; - await getPaginatedList(endpoint, filters, page, pageSize, pagination, DockerImage.fromJSON, selfprocessError); + await getPaginatedList( + endpoint, + filters, + page, + pageSize, + pagination, + DockerImage.fromJSON, + selfprocessError, + ); } async function patchDockerImage(dockerData: DockerImage, selfprocessError: boolean = true): Promise { @@ -45,7 +58,11 @@ export function useDockerImages(): DockerImagesState { await patch(endpoint, { public: dockerData.public }, response, undefined, selfprocessError); } - async function createDockerImage(dockerData: DockerImage, file: File, selfprocessError: boolean = true): Promise { + async function createDockerImage( + dockerData: DockerImage, + file: File, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.dockerImages.index; await create( endpoint, @@ -57,7 +74,7 @@ export function useDockerImages(): DockerImagesState { response, Response.fromJSON, 'multipart/form-data', - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/extra_checks.service.ts b/frontend/src/composables/services/extra_checks.service.ts index 8cac1ecd..14a6f129 100644 --- a/frontend/src/composables/services/extra_checks.service.ts +++ b/frontend/src/composables/services/extra_checks.service.ts @@ -22,7 +22,11 @@ export function useExtraCheck(): ExtraCheckState { await getList(endpoint, extraChecks, ExtraCheck.fromJSON, selfprocessError); } - async function addExtraCheck(extraCheckData: ExtraCheck, projectId: string, selfprocessError: boolean = true): Promise { + async function addExtraCheck( + extraCheckData: ExtraCheck, + projectId: string, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.extraChecks.byProject.replace('{projectId}', projectId); await create( endpoint, @@ -37,7 +41,7 @@ export function useExtraCheck(): ExtraCheckState { extraCheck, ExtraCheck.fromJSON, 'multipart/form-data', - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/faculty.service.ts b/frontend/src/composables/services/faculty.service.ts index 23fcb85f..195ce918 100644 --- a/frontend/src/composables/services/faculty.service.ts +++ b/frontend/src/composables/services/faculty.service.ts @@ -28,7 +28,14 @@ export function useFaculty(): FacultyState { async function createFaculty(facultyData: Faculty, selfprocessError: boolean = true): Promise { const endpoint = endpoints.faculties.index; - await create(endpoint, { id: facultyData.id, name: facultyData.name }, faculty, Faculty.fromJSON, undefined, selfprocessError); + await create( + endpoint, + { id: facultyData.id, name: facultyData.name }, + faculty, + Faculty.fromJSON, + undefined, + selfprocessError, + ); } async function deleteFaculty(id: string, selfprocessError: boolean = true): Promise { diff --git a/frontend/src/composables/services/group.service.ts b/frontend/src/composables/services/group.service.ts index 39d50ba7..ec748c04 100644 --- a/frontend/src/composables/services/group.service.ts +++ b/frontend/src/composables/services/group.service.ts @@ -43,7 +43,7 @@ export function useGroup(): GroupState { group, Group.fromJSON, undefined, - selfprocessError + selfprocessError, ); } diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index 14d659c2..2b4b0803 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -14,15 +14,20 @@ import { type Filter } from '@/types/filter/Filter.ts'; * @param ref * @param fromJson */ -export async function get(endpoint: string, ref: Ref, fromJson: (data: any) => T, selfprocessError: boolean = true): Promise { +export async function get( + endpoint: string, + ref: Ref, + fromJson: (data: any) => T, + selfprocessError: boolean = true, +): Promise { try { const response = await client.get(endpoint); ref.value = fromJson(response.data); } catch (error: any) { - if(selfprocessError){ + if (selfprocessError){ processError(error); console.error(error); // Log the error for debugging - }else{ + } else { throw error; // Re-throw the error to the caller } } @@ -52,10 +57,10 @@ export async function create( }); ref.value = fromJson(response.data); } catch (error: any) { - if(selfprocessError){ + if (selfprocessError){ processError(error); console.error(error); // Log the error for debugging - }else{ + } else { throw error; // Re-throw the error to the caller } } @@ -84,10 +89,10 @@ export async function patch( }); ref.value = Response.fromJSON(response.data); } catch (error: any) { - if(selfprocessError){ + if (selfprocessError){ processError(error); console.error(error); // Log the error for debugging - }else{ + } else { throw error; // Re-throw the error to the caller } } @@ -100,15 +105,20 @@ export async function patch( * @param ref * @param fromJson */ -export async function deleteId(endpoint: string, ref: Ref, fromJson: (data: any) => T, selfprocessError: boolean = true): Promise { +export async function deleteId( + endpoint: string, + ref: Ref, + fromJson: (data: any) => T, + selfprocessError: boolean = true, +): Promise { try { const response = await client.delete(endpoint); ref.value = fromJson(response.data); } catch (error: any) { - if(selfprocessError){ + if (selfprocessError){ processError(error); console.error(error); // Log the error for debugging - }else{ + } else { throw error; // Re-throw the error to the caller } } @@ -133,10 +143,10 @@ export async function deleteIdWithData( const response = await client.delete(endpoint, { data }); ref.value = fromJson(response.data); } catch (error: any) { - if(selfprocessError){ + if (selfprocessError){ processError(error); console.error(error); // Log the error for debugging - }else{ + } else { throw error; // Re-throw the error to the caller } } @@ -149,16 +159,21 @@ export async function deleteIdWithData( * @param ref * @param fromJson */ -export async function getList(endpoint: string, ref: Ref, fromJson: (data: any) => T, selfprocessError: boolean = true): Promise { +export async function getList( + endpoint: string, + ref: Ref, + fromJson: (data: any) => T, + selfprocessError: boolean = true, +): Promise { try { const response = await client.get(endpoint); ref.value = response.data.map((data: T) => fromJson(data)); } catch (error: any) { ref.value = []; // Set the ref to an empty array - if(selfprocessError){ + if (selfprocessError){ processError(error); console.error(error); // Log the error for debugging - }else{ + } else { throw error; // Re-throw the error to the caller } } @@ -204,10 +219,10 @@ export async function getPaginatedList( results: [], }; - if(selfprocessError){ + if (selfprocessError){ processError(error); console.error(error); // Log the error for debugging - }else{ + } else { throw error; // Re-throw the error to the caller } } @@ -239,7 +254,7 @@ export async function getListMerged( if(selfprocessError){ processError(error); console.error(error); // Log the error for debugging - }else{ + } else { throw error; // Re-throw the error to the caller } } diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index 63150293..92d6c7f0 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -1,7 +1,7 @@ import { Project } from '@/types/Project'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import { create, deleteId, get, getList, patch} from '@/composables/services/helpers.ts'; +import { create, deleteId, get, getList, patch } from '@/composables/services/helpers.ts'; import { type Response } from '@/types/Response.ts'; interface ProjectState { From 308f84d4ce0c086569a161b744e994076cc7421a Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 12:19:18 +0200 Subject: [PATCH 09/17] chore: fix linter --- frontend/src/composables/services/helpers.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index 2b4b0803..e9bb4144 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -24,7 +24,7 @@ export async function get( const response = await client.get(endpoint); ref.value = fromJson(response.data); } catch (error: any) { - if (selfprocessError){ + if (selfprocessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -57,7 +57,7 @@ export async function create( }); ref.value = fromJson(response.data); } catch (error: any) { - if (selfprocessError){ + if (selfprocessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -89,7 +89,7 @@ export async function patch( }); ref.value = Response.fromJSON(response.data); } catch (error: any) { - if (selfprocessError){ + if (selfprocessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -115,7 +115,7 @@ export async function deleteId( const response = await client.delete(endpoint); ref.value = fromJson(response.data); } catch (error: any) { - if (selfprocessError){ + if (selfprocessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -143,7 +143,7 @@ export async function deleteIdWithData( const response = await client.delete(endpoint, { data }); ref.value = fromJson(response.data); } catch (error: any) { - if (selfprocessError){ + if (selfprocessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -170,7 +170,7 @@ export async function getList( ref.value = response.data.map((data: T) => fromJson(data)); } catch (error: any) { ref.value = []; // Set the ref to an empty array - if (selfprocessError){ + if (selfprocessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -219,7 +219,7 @@ export async function getPaginatedList( results: [], }; - if (selfprocessError){ + if (selfprocessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -251,7 +251,7 @@ export async function getListMerged( allData.push(...responseData); // Merge into the allData array } catch (error: any) { ref.value = []; // Set the ref to an empty array - if(selfprocessError){ + if (selfprocessError){ processError(error); console.error(error); // Log the error for debugging } else { From c171a390d41313cddfd775507009a2610a86247a Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Tue, 21 May 2024 12:22:00 +0200 Subject: [PATCH 10/17] chore: fix linter --- frontend/src/composables/services/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index e9bb4144..ea90461f 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -251,7 +251,7 @@ export async function getListMerged( allData.push(...responseData); // Merge into the allData array } catch (error: any) { ref.value = []; // Set the ref to an empty array - if (selfprocessError){ + if (selfprocessError) { processError(error); console.error(error); // Log the error for debugging } else { From 5c0ca72422a3ee2ecd95145788ec2858df308a7b Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Wed, 22 May 2024 12:15:14 +0200 Subject: [PATCH 11/17] chore: fix linter --- .../services/extra_checks.service.ts | 6 +++++- frontend/src/composables/services/helpers.ts | 20 ++++++++++++++----- .../services/structure_check.service.ts | 14 ++++++++++--- .../services/submission.service.ts | 7 +------ 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/frontend/src/composables/services/extra_checks.service.ts b/frontend/src/composables/services/extra_checks.service.ts index 183af86a..39ef35d6 100644 --- a/frontend/src/composables/services/extra_checks.service.ts +++ b/frontend/src/composables/services/extra_checks.service.ts @@ -46,7 +46,11 @@ export function useExtraCheck(): ExtraCheckState { ); } - async function setExtraChecks(extraChecks: ExtraCheck[], projectId: string, selfprocessError: boolean = true): Promise { + async function setExtraChecks( + extraChecks: ExtraCheck[], + projectId: string, + selfprocessError: boolean = true, + ): Promise { for (const extraCheck of extraChecks) { if (extraCheck.id === '') { await addExtraCheck(extraCheck, projectId, selfprocessError); diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index e255a2d5..d2cfd2d8 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -110,12 +110,22 @@ export async function put( endpoint: string, data: T | string, contentType: string = 'application/json', + selfprocessError: boolean = true, ): Promise { - await client.put(endpoint, data, { - headers: { - 'Content-Type': contentType, - }, - }); + try { + await client.put(endpoint, data, { + headers: { + 'Content-Type': contentType, + }, + }); + } catch (error: any) { + if (selfprocessError) { + processError(error); + console.error(error); // Log the error for debugging + } else { + throw error; // Re-throw the error to the caller + } + } } /** diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index 15abc610..b6cd3658 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -6,7 +6,7 @@ import { get, getList, create, deleteId, put } from '@/composables/services/help interface StructureCheckState { structureChecks: Ref; structureCheck: Ref; - + getStructureCheckByID: (id: string, selfprocessError?: boolean) => Promise; getStructureCheckByProject: (projectId: string, selfprocessError?: boolean) => Promise; createStructureCheck: ( @@ -14,7 +14,11 @@ interface StructureCheckState { projectId: string, selfprocessError?: boolean, ) => Promise; - setStructureChecks: (structureChecks: StructureCheck[], projectId: string, selfprocessError?: boolean) => Promise; + setStructureChecks: ( + structureChecks: StructureCheck[], + projectId: string, + selfprocessError?: boolean + ) => Promise; deleteStructureCheck: (id: string, selfprocessError?: boolean) => Promise; } @@ -50,7 +54,11 @@ export function useStructureCheck(): StructureCheckState { ); } - async function setStructureChecks(structureChecks: StructureCheck[], projectId: string, selfprocessError: boolean = true): Promise { + async function setStructureChecks( + structureChecks: StructureCheck[], + projectId: string, + selfprocessError: boolean = true, + ): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); await put(endpoint, structureChecks, undefined, selfprocessError); } diff --git a/frontend/src/composables/services/submission.service.ts b/frontend/src/composables/services/submission.service.ts index 002d73f2..6b04ed41 100644 --- a/frontend/src/composables/services/submission.service.ts +++ b/frontend/src/composables/services/submission.service.ts @@ -44,12 +44,7 @@ export function useSubmission(): SubmissionState { formData.append('files', file); // Gebruik 'files' in plaats van 'files[]' }); await create( - endpoint, - formData, - submission, - Submission.fromJSON, - 'multipart/form-data', - selfprocessError, + endpoint, formData, submission, Submission.fromJSON, 'multipart/form-data', selfprocessError, ); } From 5d06d7bbb39992826d60913ead50b15ee5205cf2 Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Wed, 22 May 2024 13:04:17 +0200 Subject: [PATCH 12/17] chore: fix linter --- frontend/src/composables/services/structure_check.service.ts | 2 +- frontend/src/composables/services/submission.service.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index b6cd3658..6e2a984a 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -17,7 +17,7 @@ interface StructureCheckState { setStructureChecks: ( structureChecks: StructureCheck[], projectId: string, - selfprocessError?: boolean + selfprocessError?: boolean, ) => Promise; deleteStructureCheck: (id: string, selfprocessError?: boolean) => Promise; } diff --git a/frontend/src/composables/services/submission.service.ts b/frontend/src/composables/services/submission.service.ts index 6b04ed41..609ceadb 100644 --- a/frontend/src/composables/services/submission.service.ts +++ b/frontend/src/composables/services/submission.service.ts @@ -43,9 +43,7 @@ export function useSubmission(): SubmissionState { uploadedFiles.forEach((file: File) => { formData.append('files', file); // Gebruik 'files' in plaats van 'files[]' }); - await create( - endpoint, formData, submission, Submission.fromJSON, 'multipart/form-data', selfprocessError, - ); + await create(endpoint, formData, submission, Submission.fromJSON, 'multipart/form-data', selfprocessError); } async function deleteSubmission(id: string, selfprocessError: boolean = true): Promise { From 1e67c9dfbf87887ba584e285cdcc68b5b5cee2b8 Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Thu, 23 May 2024 09:53:51 +0200 Subject: [PATCH 13/17] chore: first part of merge --- frontend/src/composables/services/project.service.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index 32c47b75..d6664d17 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -1,4 +1,4 @@ -import { Project } from '@/types/Project'; +import { Project, ProjectJSON } from '@/types/Project'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; import { i18n } from '@/config/i18n.ts'; @@ -62,7 +62,7 @@ export function useProject(): ProjectState { selfprocessError: boolean = true, ): Promise { await getProjectsByCourse(courseId, selfprocessError); - const allProjects = (projects.value ?? []).map((projectData: Project) => Project.fromJSON(projectData)); + const allProjects = (projects.value ?? []).map((projectData: ProjectJSON) => Project.fromJSON(projectData)); projects.value = allProjects.filter((project: Project) => { return project.deadline.toDateString() === deadlineDate.toDateString(); }); @@ -105,6 +105,7 @@ export function useProject(): ProjectState { Project.fromJSON, 'multipart/form-data', selfprocessError, + ); addSuccessMessage( t('toasts.messages.success'), t('toasts.messages.projects.create.success', [project.value?.name]), From 4a7148c835abdde44160d32399c8240d2e75fb4d Mon Sep 17 00:00:00 2001 From: EwoutV Date: Thu, 23 May 2024 09:58:00 +0200 Subject: [PATCH 14/17] fix: project service --- .../src/composables/services/admin.service.ts | 24 +++--- .../composables/services/assistant.service.ts | 48 ++++++------ .../composables/services/course.service.ts | 76 +++++++++---------- .../composables/services/docker.service.ts | 36 ++++----- .../services/extra_checks.service.ts | 24 +++--- .../composables/services/faculty.service.ts | 24 +++--- .../src/composables/services/group.service.ts | 30 ++++---- frontend/src/composables/services/helpers.ts | 32 ++++---- .../composables/services/project.service.ts | 64 ++++++++-------- .../services/structure_check.service.ts | 30 ++++---- .../composables/services/student.service.ts | 60 +++++++-------- .../services/submission.service.ts | 30 ++++---- .../services/submission_status.service.ts | 6 +- .../composables/services/teacher.service.ts | 48 ++++++------ .../src/composables/services/users.service.ts | 30 ++++---- 15 files changed, 282 insertions(+), 280 deletions(-) diff --git a/frontend/src/composables/services/admin.service.ts b/frontend/src/composables/services/admin.service.ts index a1fb1c50..5b576414 100644 --- a/frontend/src/composables/services/admin.service.ts +++ b/frontend/src/composables/services/admin.service.ts @@ -6,27 +6,27 @@ import { User } from '@/types/users/User.ts'; interface AdminState { admins: Ref; admin: Ref; - getAdminByID: (id: string, selfprocessError?: boolean) => Promise; - getAdmins: (selfprocessError?: boolean) => Promise; - createAdmin: (adminData: User, selfprocessError?: boolean) => Promise; - deleteAdmin: (id: string, selfprocessError?: boolean) => Promise; + getAdminByID: (id: string, selfProcessError?: boolean) => Promise; + getAdmins: (selfProcessError?: boolean) => Promise; + createAdmin: (adminData: User, selfProcessError?: boolean) => Promise; + deleteAdmin: (id: string, selfProcessError?: boolean) => Promise; } export function useAdmin(): AdminState { const admins = ref(null); const admin = ref(null); - async function getAdminByID(id: string, selfprocessError: boolean = true): Promise { + async function getAdminByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.admins.retrieve.replace('{id}', id); - await get(endpoint, admin, User.fromJSON, selfprocessError); + await get(endpoint, admin, User.fromJSON, selfProcessError); } - async function getAdmins(selfprocessError: boolean = true): Promise { + async function getAdmins(selfProcessError: boolean = true): Promise { const endpoint = endpoints.admins.index; - await getList(endpoint, admins, User.fromJSON, selfprocessError); + await getList(endpoint, admins, User.fromJSON, selfProcessError); } - async function createAdmin(user: User, selfprocessError: boolean = true): Promise { + async function createAdmin(user: User, selfProcessError: boolean = true): Promise { const endpoint = endpoints.admins.index; await createToast( 'admin', @@ -37,13 +37,13 @@ export function useAdmin(): AdminState { admin, User.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } - async function deleteAdmin(id: string, selfprocessError: boolean = true): Promise { + async function deleteAdmin(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.admins.retrieve.replace('{id}', id); - await deleteId(endpoint, admin, User.fromJSON, selfprocessError); + await deleteId(endpoint, admin, User.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index 7239469b..c2e5eff3 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -20,14 +20,14 @@ interface AssistantState { assistant: Ref; response: Ref; assistantPagination: Ref | null>; - getAssistantByID: (id: string, init?: boolean, selfprocessError?: boolean) => Promise; - getAssistantsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; - getAssistants: (selfprocessError?: boolean) => Promise; - searchAssistants: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; - assistantJoinCourse: (courseId: string, assistantId: string, selfprocessError?: boolean) => Promise; - assistantLeaveCourse: (courseId: string, assistantId: string, selfprocessError?: boolean) => Promise; - createAssistant: (assistantData: Assistant, selfprocessError?: boolean) => Promise; - deleteAssistant: (id: string, selfprocessError?: boolean) => Promise; + getAssistantByID: (id: string, init?: boolean, selfProcessError?: boolean) => Promise; + getAssistantsByCourse: (courseId: string, selfProcessError?: boolean) => Promise; + getAssistants: (selfProcessError?: boolean) => Promise; + searchAssistants: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + assistantJoinCourse: (courseId: string, assistantId: string, selfProcessError?: boolean) => Promise; + assistantLeaveCourse: (courseId: string, assistantId: string, selfProcessError?: boolean) => Promise; + createAssistant: (assistantData: Assistant, selfProcessError?: boolean) => Promise; + deleteAssistant: (id: string, selfProcessError?: boolean) => Promise; } export function useAssistant(): AssistantState { @@ -37,26 +37,26 @@ export function useAssistant(): AssistantState { const response = ref(null); const assistantPagination = ref | null>(null); - async function getAssistantByID(id: string, selfprocessError: boolean = true): Promise { + async function getAssistantByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.retrieve.replace('{id}', id); - await get(endpoint, assistant, Assistant.fromJSON, selfprocessError); + await get(endpoint, assistant, Assistant.fromJSON, selfProcessError); } - async function getAssistantsByCourse(courseId: string, selfprocessError: boolean = true): Promise { + async function getAssistantsByCourse(courseId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); - await getList(endpoint, assistants, Assistant.fromJSON, selfprocessError); + await getList(endpoint, assistants, Assistant.fromJSON, selfProcessError); } - async function getAssistants(selfprocessError: boolean = true): Promise { + async function getAssistants(selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.index; - await getList(endpoint, assistants, Assistant.fromJSON, selfprocessError); + await getList(endpoint, assistants, Assistant.fromJSON, selfProcessError); } async function searchAssistants( filters: Filter, page: number, pageSize: number, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.assistants.search; await getPaginatedList( @@ -66,14 +66,14 @@ export function useAssistant(): AssistantState { pageSize, assistantPagination, Assistant.fromJSON, - selfprocessError, + selfProcessError, ); } async function assistantJoinCourse( courseId: string, assistantId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); await create( @@ -82,14 +82,14 @@ export function useAssistant(): AssistantState { response, Response.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } async function assistantLeaveCourse( courseId: string, assistantId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId); await deleteIdWithData( @@ -97,11 +97,11 @@ export function useAssistant(): AssistantState { { assistant: assistantId }, response, Response.fromJSON, - selfprocessError, + selfProcessError, ); } - async function createAssistant(user: User, selfprocessError: boolean = true): Promise { + async function createAssistant(user: User, selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.index; await createToast( 'assistant', @@ -112,13 +112,13 @@ export function useAssistant(): AssistantState { assistant, Assistant.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } - async function deleteAssistant(id: string, selfprocessError: boolean = true): Promise { + async function deleteAssistant(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.assistants.retrieve.replace('{id}', id); - await deleteId(endpoint, assistant, Assistant.fromJSON, selfprocessError); + await deleteId(endpoint, assistant, Assistant.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/course.service.ts b/frontend/src/composables/services/course.service.ts index 9e45620a..89c99247 100644 --- a/frontend/src/composables/services/course.service.ts +++ b/frontend/src/composables/services/course.service.ts @@ -14,23 +14,23 @@ interface CoursesState { courses: Ref; course: Ref; - getCourseByID: (id: string, selfprocessError?: boolean) => Promise; - getCourses: (selfprocessError?: boolean) => Promise; - searchCourses: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; - getCoursesByStudent: (studentId: string, selfprocessError?: boolean) => Promise; - getCoursesByTeacher: (teacherId: string, selfprocessError?: boolean) => Promise; - getCourseByAssistant: (assistantId: string, selfprocessError?: boolean) => Promise; - getCoursesByUser: (user: User, selfprocessError?: boolean) => Promise; - createCourse: (courseData: Course, selfprocessError?: boolean) => Promise; - updateCourse: (courseData: Course, selfprocessError?: boolean) => Promise; + getCourseByID: (id: string, selfProcessError?: boolean) => Promise; + getCourses: (selfProcessError?: boolean) => Promise; + searchCourses: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + getCoursesByStudent: (studentId: string, selfProcessError?: boolean) => Promise; + getCoursesByTeacher: (teacherId: string, selfProcessError?: boolean) => Promise; + getCourseByAssistant: (assistantId: string, selfProcessError?: boolean) => Promise; + getCoursesByUser: (user: User, selfProcessError?: boolean) => Promise; + createCourse: (courseData: Course, selfProcessError?: boolean) => Promise; + updateCourse: (courseData: Course, selfProcessError?: boolean) => Promise; cloneCourse: ( courseId: string, cloneAssistants: boolean, cloneTeachers: boolean, - selfprocessError?: boolean, + selfProcessError?: boolean, ) => Promise; - activateInvitationLink: (courseId: string, linkDuration: number, selfprocessError?: boolean) => Promise; - deleteCourse: (id: string, selfprocessError?: boolean) => Promise; + activateInvitationLink: (courseId: string, linkDuration: number, selfProcessError?: boolean) => Promise; + deleteCourse: (id: string, selfProcessError?: boolean) => Promise; } export function useCourses(): CoursesState { @@ -39,21 +39,21 @@ export function useCourses(): CoursesState { const course = ref(null); const response = ref(null); - async function getCourseByID(id: string, selfprocessError: boolean = true): Promise { + async function getCourseByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.retrieve.replace('{id}', id); - await get(endpoint, course, Course.fromJSON, selfprocessError); + await get(endpoint, course, Course.fromJSON, selfProcessError); } - async function getCourses(selfprocessError: boolean = true): Promise { + async function getCourses(selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.index; - await getList(endpoint, courses, Course.fromJSON, selfprocessError); + await getList(endpoint, courses, Course.fromJSON, selfProcessError); } async function searchCourses( filters: Filter, page: number, pageSize: number, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.courses.search; await getPaginatedList( @@ -63,38 +63,38 @@ export function useCourses(): CoursesState { pageSize, pagination, Course.fromJSON, - selfprocessError, + selfProcessError, ); } - async function getCoursesByStudent(studentId: string, selfprocessError: boolean = true): Promise { + async function getCoursesByStudent(studentId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.byStudent.replace('{studentId}', studentId); - await getList(endpoint, courses, Course.fromJSON, selfprocessError); + await getList(endpoint, courses, Course.fromJSON, selfProcessError); } - async function getCoursesByTeacher(teacherId: string, selfprocessError: boolean = true): Promise { + async function getCoursesByTeacher(teacherId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.byTeacher.replace('{teacherId}', teacherId); - await getList(endpoint, courses, Course.fromJSON, selfprocessError); + await getList(endpoint, courses, Course.fromJSON, selfProcessError); } - async function getCourseByAssistant(assistantId: string, selfprocessError: boolean = true): Promise { + async function getCourseByAssistant(assistantId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.byAssistant.replace('{assistantId}', assistantId); - await getList(endpoint, courses, Course.fromJSON, selfprocessError); + await getList(endpoint, courses, Course.fromJSON, selfProcessError); } - async function getCoursesByUser(user: User, selfprocessError: boolean = true): Promise { + async function getCoursesByUser(user: User, selfProcessError: boolean = true): Promise { if (user.isTeacher()) { - await getCoursesByTeacher(user.id, selfprocessError); + await getCoursesByTeacher(user.id, selfProcessError); } else if (user.isAssistant()) { - await getCourseByAssistant(user.id, selfprocessError); + await getCourseByAssistant(user.id, selfProcessError); } else if (user.isStudent()) { - await getCoursesByStudent(user.id, selfprocessError); + await getCoursesByStudent(user.id, selfProcessError); } else { courses.value = []; } } - async function createCourse(courseData: Course, selfprocessError: boolean = true): Promise { + async function createCourse(courseData: Course, selfProcessError: boolean = true): Promise { const { t } = i18n.global; const { addSuccessMessage } = useMessagesStore(); const endpoint = endpoints.courses.index; @@ -112,7 +112,7 @@ export function useCourses(): CoursesState { course, Course.fromJSON, undefined, - selfprocessError, + selfProcessError, ); addSuccessMessage( t('toasts.messages.success'), @@ -120,7 +120,7 @@ export function useCourses(): CoursesState { ); } - async function updateCourse(courseData: Course, selfprocessError: boolean = true): Promise { + async function updateCourse(courseData: Course, selfProcessError: boolean = true): Promise { // Endpoint to update is same as retrieve const endpoint = endpoints.courses.retrieve.replace('{id}', courseData.id); @@ -136,7 +136,7 @@ export function useCourses(): CoursesState { }, response, undefined, - selfprocessError, + selfProcessError, ); } @@ -144,7 +144,7 @@ export function useCourses(): CoursesState { courseId: string, cloneAssistants: boolean, cloneTeachers: boolean, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.courses.clone.replace('{courseId}', courseId); await create( @@ -156,19 +156,19 @@ export function useCourses(): CoursesState { course, Course.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } - async function deleteCourse(id: string, selfprocessError: boolean = true): Promise { + async function deleteCourse(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.courses.retrieve.replace('{id}', id); - await deleteId(endpoint, course, Course.fromJSON, selfprocessError); + await deleteId(endpoint, course, Course.fromJSON, selfProcessError); } async function activateInvitationLink( courseId: string, linkDuration: number, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.courses.invitationLink.replace('{courseId}', courseId); await patch( @@ -178,7 +178,7 @@ export function useCourses(): CoursesState { }, response, undefined, - selfprocessError, + selfProcessError, ); } diff --git a/frontend/src/composables/services/docker.service.ts b/frontend/src/composables/services/docker.service.ts index 2034cf72..6ed450f2 100644 --- a/frontend/src/composables/services/docker.service.ts +++ b/frontend/src/composables/services/docker.service.ts @@ -17,12 +17,12 @@ interface DockerImagesState { pagination: Ref | null>; dockerImages: Ref; response: Ref; - getDockerImages: (selfprocessError?: boolean) => Promise; - searchDockerImages: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; - patchDockerImage: (dockerData: DockerImage, selfprocessError?: boolean) => Promise; - createDockerImage: (dockerData: DockerImage, file: File, selfprocessError?: boolean) => Promise; - deleteDockerImage: (id: string, selfprocessError?: boolean) => Promise; - deleteDockerImages: (ids: string[], selfprocessError?: boolean) => Promise; + getDockerImages: (selfProcessError?: boolean) => Promise; + searchDockerImages: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + patchDockerImage: (dockerData: DockerImage, selfProcessError?: boolean) => Promise; + createDockerImage: (dockerData: DockerImage, file: File, selfProcessError?: boolean) => Promise; + deleteDockerImage: (id: string, selfProcessError?: boolean) => Promise; + deleteDockerImages: (ids: string[], selfProcessError?: boolean) => Promise; } export function useDockerImages(): DockerImagesState { @@ -30,16 +30,16 @@ export function useDockerImages(): DockerImagesState { const dockerImages = ref(null); const response = ref(null); - async function getDockerImages(selfprocessError: boolean = true): Promise { + async function getDockerImages(selfProcessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.index; - await getList(endpoint, dockerImages, DockerImage.fromJSON, selfprocessError); + await getList(endpoint, dockerImages, DockerImage.fromJSON, selfProcessError); } async function searchDockerImages( filters: Filter, page: number, pageSize: number, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.dockerImages.search; await getPaginatedList( @@ -49,19 +49,19 @@ export function useDockerImages(): DockerImagesState { pageSize, pagination, DockerImage.fromJSON, - selfprocessError, + selfProcessError, ); } - async function patchDockerImage(dockerData: DockerImage, selfprocessError: boolean = true): Promise { + async function patchDockerImage(dockerData: DockerImage, selfProcessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.patch.replace('{id}', dockerData.id); - await patch(endpoint, { public: dockerData.public }, response, undefined, selfprocessError); + await patch(endpoint, { public: dockerData.public }, response, undefined, selfProcessError); } async function createDockerImage( dockerData: DockerImage, file: File, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.dockerImages.index; await createToast( @@ -75,19 +75,19 @@ export function useDockerImages(): DockerImagesState { response, Response.fromJSON, 'multipart/form-data', - selfprocessError, + selfProcessError, ); } - async function deleteDockerImage(id: string, selfprocessError: boolean = true): Promise { + async function deleteDockerImage(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.retrieve.replace('{id}', id); - await deleteId(endpoint, response, Response.fromJSON, selfprocessError); + await deleteId(endpoint, response, Response.fromJSON, selfProcessError); } - async function deleteDockerImages(ids: string[], selfprocessError: boolean = true): Promise { + async function deleteDockerImages(ids: string[], selfProcessError: boolean = true): Promise { const endpoint = endpoints.dockerImages.deleteMany; const data = { ids }; - await deleteIdWithData(endpoint, data, response, Response.fromJSON, selfprocessError); + await deleteIdWithData(endpoint, data, response, Response.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/extra_checks.service.ts b/frontend/src/composables/services/extra_checks.service.ts index 39ef35d6..1e7a99f1 100644 --- a/frontend/src/composables/services/extra_checks.service.ts +++ b/frontend/src/composables/services/extra_checks.service.ts @@ -7,10 +7,10 @@ import { Response } from '@/types/Response'; interface ExtraCheckState { extraCheck: Ref; extraChecks: Ref; - getExtraChecksByProject: (projectId: string, selfprocessError?: boolean) => Promise; - addExtraCheck: (extraCheckData: ExtraCheck, projectId: string, selfprocessError?: boolean) => Promise; - setExtraChecks: (extraChecks: ExtraCheck[], projectId: string, selfprocessError?: boolean) => Promise; - deleteExtraCheck: (extraCheckId: string, selfprocessError?: boolean) => Promise; + getExtraChecksByProject: (projectId: string, selfProcessError?: boolean) => Promise; + addExtraCheck: (extraCheckData: ExtraCheck, projectId: string, selfProcessError?: boolean) => Promise; + setExtraChecks: (extraChecks: ExtraCheck[], projectId: string, selfProcessError?: boolean) => Promise; + deleteExtraCheck: (extraCheckId: string, selfProcessError?: boolean) => Promise; } export function useExtraCheck(): ExtraCheckState { @@ -18,15 +18,15 @@ export function useExtraCheck(): ExtraCheckState { const extraChecks = ref(null); const response = ref(null); - async function getExtraChecksByProject(projectId: string, selfprocessError: boolean = true): Promise { + async function getExtraChecksByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.extraChecks.byProject.replace('{projectId}', projectId); - await getList(endpoint, extraChecks, ExtraCheck.fromJSON, selfprocessError); + await getList(endpoint, extraChecks, ExtraCheck.fromJSON, selfProcessError); } async function addExtraCheck( extraCheckData: ExtraCheck, projectId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.extraChecks.byProject.replace('{projectId}', projectId); await create( @@ -42,25 +42,25 @@ export function useExtraCheck(): ExtraCheckState { extraCheck, ExtraCheck.fromJSON, 'multipart/form-data', - selfprocessError, + selfProcessError, ); } async function setExtraChecks( extraChecks: ExtraCheck[], projectId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { for (const extraCheck of extraChecks) { if (extraCheck.id === '') { - await addExtraCheck(extraCheck, projectId, selfprocessError); + await addExtraCheck(extraCheck, projectId, selfProcessError); } } } - async function deleteExtraCheck(extraCheckId: string, selfprocessError: boolean = true): Promise { + async function deleteExtraCheck(extraCheckId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.extraChecks.retrieve.replace('{id}', extraCheckId); - await deleteId(endpoint, response, Response.fromJSON, selfprocessError); + await deleteId(endpoint, response, Response.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/faculty.service.ts b/frontend/src/composables/services/faculty.service.ts index 0bfafa1d..6c2c31f4 100644 --- a/frontend/src/composables/services/faculty.service.ts +++ b/frontend/src/composables/services/faculty.service.ts @@ -6,27 +6,27 @@ import { get, getList, deleteId, createToast } from '@/composables/services/help interface FacultyState { faculties: Ref; faculty: Ref; - getFacultyByID: (id: string, selfprocessError?: boolean) => Promise; - getFaculties: (selfprocessError?: boolean) => Promise; - createFaculty: (facultyData: Faculty, selfprocessError?: boolean) => Promise; - deleteFaculty: (id: string, selfprocessError?: boolean) => Promise; + getFacultyByID: (id: string, selfProcessError?: boolean) => Promise; + getFaculties: (selfProcessError?: boolean) => Promise; + createFaculty: (facultyData: Faculty, selfProcessError?: boolean) => Promise; + deleteFaculty: (id: string, selfProcessError?: boolean) => Promise; } export function useFaculty(): FacultyState { const faculties = ref(null); const faculty = ref(null); - async function getFacultyByID(id: string, selfprocessError: boolean = true): Promise { + async function getFacultyByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.faculties.retrieve.replace('{id}', id); - await get(endpoint, faculty, Faculty.fromJSON, selfprocessError); + await get(endpoint, faculty, Faculty.fromJSON, selfProcessError); } - async function getFaculties(selfprocessError: boolean = true): Promise { + async function getFaculties(selfProcessError: boolean = true): Promise { const endpoint = endpoints.faculties.index; - await getList(endpoint, faculties, Faculty.fromJSON, selfprocessError); + await getList(endpoint, faculties, Faculty.fromJSON, selfProcessError); } - async function createFaculty(facultyData: Faculty, selfprocessError: boolean = true): Promise { + async function createFaculty(facultyData: Faculty, selfProcessError: boolean = true): Promise { const endpoint = endpoints.faculties.index; await createToast( 'faculty', @@ -35,13 +35,13 @@ export function useFaculty(): FacultyState { faculty, Faculty.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } - async function deleteFaculty(id: string, selfprocessError: boolean = true): Promise { + async function deleteFaculty(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.faculties.retrieve.replace('{id}', id); - await deleteId(endpoint, faculty, Faculty.fromJSON, selfprocessError); + await deleteId(endpoint, faculty, Faculty.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/group.service.ts b/frontend/src/composables/services/group.service.ts index ec748c04..a810d429 100644 --- a/frontend/src/composables/services/group.service.ts +++ b/frontend/src/composables/services/group.service.ts @@ -6,33 +6,33 @@ import { get, getList, create, deleteId } from '@/composables/services/helpers.t interface GroupState { groups: Ref; group: Ref; - getGroupByID: (id: string, selfprocessError?: boolean) => Promise; - getGroupsByProject: (projectId: string, selfprocessError?: boolean) => Promise; - getGroupsByStudent: (studentId: string, selfprocessError?: boolean) => Promise; - createGroup: (groupData: Group, projectId: string, selfprocessError?: boolean) => Promise; - deleteGroup: (id: string, selfprocessError?: boolean) => Promise; + getGroupByID: (id: string, selfProcessError?: boolean) => Promise; + getGroupsByProject: (projectId: string, selfProcessError?: boolean) => Promise; + getGroupsByStudent: (studentId: string, selfProcessError?: boolean) => Promise; + createGroup: (groupData: Group, projectId: string, selfProcessError?: boolean) => Promise; + deleteGroup: (id: string, selfProcessError?: boolean) => Promise; } export function useGroup(): GroupState { const groups = ref(null); const group = ref(null); - async function getGroupByID(id: string, selfprocessError: boolean = true): Promise { + async function getGroupByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.retrieve.replace('{id}', id); - await get(endpoint, group, Group.fromJSON, selfprocessError); + await get(endpoint, group, Group.fromJSON, selfProcessError); } - async function getGroupsByProject(projectId: string, selfprocessError: boolean = true): Promise { + async function getGroupsByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.byProject.replace('{projectId}', projectId); - await getList(endpoint, groups, Group.fromJSON, selfprocessError); + await getList(endpoint, groups, Group.fromJSON, selfProcessError); } - async function getGroupsByStudent(studentId: string, selfprocessError: boolean = true): Promise { + async function getGroupsByStudent(studentId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.byStudent.replace('{studentId}', studentId); - await getList(endpoint, groups, Group.fromJSON, selfprocessError); + await getList(endpoint, groups, Group.fromJSON, selfProcessError); } - async function createGroup(groupData: Group, projectId: string, selfprocessError: boolean = true): Promise { + async function createGroup(groupData: Group, projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.byProject.replace('{projectId}', projectId); await create( endpoint, @@ -43,13 +43,13 @@ export function useGroup(): GroupState { group, Group.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } - async function deleteGroup(id: string, selfprocessError: boolean = true): Promise { + async function deleteGroup(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.groups.retrieve.replace('{id}', id); - await deleteId(endpoint, group, Group.fromJSON, selfprocessError); + await deleteId(endpoint, group, Group.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/helpers.ts b/frontend/src/composables/services/helpers.ts index e3a4a2ca..31f9d0f3 100644 --- a/frontend/src/composables/services/helpers.ts +++ b/frontend/src/composables/services/helpers.ts @@ -18,13 +18,13 @@ export async function get( endpoint: string, ref: Ref, fromJson: (data: any) => T, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { try { const response = await client.get(endpoint); ref.value = fromJson(response.data); } catch (error: any) { - if (selfprocessError) { + if (selfProcessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -48,7 +48,7 @@ export async function create( ref: Ref, fromJson: (data: any) => T, contentType: string = 'application/json', - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { try { const response = await client.post(endpoint, data, { @@ -58,7 +58,7 @@ export async function create( }); ref.value = fromJson(response.data); } catch (error: any) { - if (selfprocessError) { + if (selfProcessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -105,7 +105,7 @@ export async function patch( data: any, ref: Ref, contentType: string = 'application/json', - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { try { const response: AxiosResponse = await client.patch(endpoint, data, { @@ -115,7 +115,7 @@ export async function patch( }); ref.value = Response.fromJSON(response.data); } catch (error: any) { - if (selfprocessError) { + if (selfProcessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -135,7 +135,7 @@ export async function put( endpoint: string, data: T | string, contentType: string = 'application/json', - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { try { await client.put(endpoint, data, { @@ -144,7 +144,7 @@ export async function put( }, }); } catch (error: any) { - if (selfprocessError) { + if (selfProcessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -164,13 +164,13 @@ export async function deleteId( endpoint: string, ref: Ref, fromJson: (data: any) => T, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { try { const response = await client.delete(endpoint); ref.value = fromJson(response.data); } catch (error: any) { - if (selfprocessError) { + if (selfProcessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -192,13 +192,13 @@ export async function deleteIdWithData( data: any, ref: Ref, fromJson: (data: any) => T, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { try { const response = await client.delete(endpoint, { data }); ref.value = fromJson(response.data); } catch (error: any) { - if (selfprocessError) { + if (selfProcessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -218,14 +218,14 @@ export async function getList( endpoint: string, ref: Ref, fromJson: (data: any) => T, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { try { const response = await client.get(endpoint); ref.value = response.data.map((data: T) => fromJson(data)); } catch (error: any) { ref.value = []; // Set the ref to an empty array - if (selfprocessError) { + if (selfProcessError) { processError(error); console.error(error); // Log the error for debugging } else { @@ -251,7 +251,7 @@ export async function getPaginatedList( pageSize: number, pagination: Ref | null>, fromJson: (data: any) => T, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { try { const response = await client.get(endpoint, { @@ -274,7 +274,7 @@ export async function getPaginatedList( results: [], }; - if (selfprocessError) { + if (selfProcessError) { processError(error); console.error(error); // Log the error for debugging } else { diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index d6664d17..97d8a81d 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -10,20 +10,20 @@ import { useMessagesStore } from '@/store/messages.store.ts'; interface ProjectState { projects: Ref; project: Ref; - getProjectByID: (id: string, selfprocessError?: boolean) => Promise; - getProjectsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; - getProjectsByStudent: (studentId: string, selfprocessError?: boolean) => Promise; - getProjectsByAssistant: (assistantId: string, selfprocessError?: boolean) => Promise; - getProjectsByTeacher: (teacherId: string, selfprocessError?: boolean) => Promise; - getProjectsByCourseAndDeadline: (courseId: string, deadlineDate: Date, selfprocessError?: boolean) => Promise; + getProjectByID: (id: string, selfProcessError?: boolean) => Promise; + getProjectsByCourse: (courseId: string, selfProcessError?: boolean) => Promise; + getProjectsByStudent: (studentId: string, selfProcessError?: boolean) => Promise; + getProjectsByAssistant: (assistantId: string, selfProcessError?: boolean) => Promise; + getProjectsByTeacher: (teacherId: string, selfProcessError?: boolean) => Promise; + getProjectsByCourseAndDeadline: (courseId: string, deadlineDate: Date, selfProcessError?: boolean) => Promise; createProject: ( projectData: Project, courseId: string, numberOfGroups: number, - selfprocessError?: boolean, + selfProcessError?: boolean, ) => Promise; - updateProject: (projectData: Project, selfprocessError?: boolean) => Promise; - deleteProject: (id: string, selfprocessError?: boolean) => Promise; + updateProject: (projectData: Project, selfProcessError?: boolean) => Promise; + deleteProject: (id: string, selfProcessError?: boolean) => Promise; } export function useProject(): ProjectState { @@ -31,48 +31,50 @@ export function useProject(): ProjectState { const project = ref(null); const response = ref(null); - async function getProjectByID(id: string, selfprocessError: boolean = true): Promise { + async function getProjectByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.retrieve.replace('{id}', id); - await get(endpoint, project, Project.fromJSON, selfprocessError); + await get(endpoint, project, Project.fromJSON, selfProcessError); } - async function getProjectsByCourse(courseId: string, selfprocessError: boolean = true): Promise { + async function getProjectsByCourse(courseId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.byCourse.replace('{courseId}', courseId); - await getList(endpoint, projects, Project.fromJSON, selfprocessError); + await getList(endpoint, projects, Project.fromJSON, selfProcessError); } - async function getProjectsByStudent(studentId: string, selfprocessError: boolean = true): Promise { + async function getProjectsByStudent(studentId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.byStudent.replace('{studentId}', studentId); - await getList(endpoint, projects, Project.fromJSON, selfprocessError); + await getList(endpoint, projects, Project.fromJSON, selfProcessError); } - async function getProjectsByAssistant(assistantId: string, selfprocessError: boolean = true): Promise { + async function getProjectsByAssistant(assistantId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.byAssistant.replace('{assistantId}', assistantId); - await getList(endpoint, projects, Project.fromJSON, selfprocessError); + await getList(endpoint, projects, Project.fromJSON, selfProcessError); } - async function getProjectsByTeacher(teacherId: string, selfprocessError: boolean = true): Promise { + async function getProjectsByTeacher(teacherId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.byTeacher.replace('{teacherId}', teacherId); - await getList(endpoint, projects, Project.fromJSON, selfprocessError); + await getList(endpoint, projects, Project.fromJSON, selfProcessError); } async function getProjectsByCourseAndDeadline( courseId: string, deadlineDate: Date, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { - await getProjectsByCourse(courseId, selfprocessError); - const allProjects = (projects.value ?? []).map((projectData: ProjectJSON) => Project.fromJSON(projectData)); - projects.value = allProjects.filter((project: Project) => { - return project.deadline.toDateString() === deadlineDate.toDateString(); - }); + await getProjectsByCourse(courseId, selfProcessError); + + if (projects.value !== null) { + projects.value = projects.value.filter((project: Project) => { + return project.deadline.toDateString() === deadlineDate.toDateString(); + }); + } } async function createProject( projectData: Project, courseId: string, numberOfGroups: number, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const { t } = i18n.global; const { addSuccessMessage } = useMessagesStore(); @@ -104,7 +106,7 @@ export function useProject(): ProjectState { project, Project.fromJSON, 'multipart/form-data', - selfprocessError, + selfProcessError, ); addSuccessMessage( t('toasts.messages.success'), @@ -112,7 +114,7 @@ export function useProject(): ProjectState { ); } - async function updateProject(projectData: Project, selfprocessError: boolean = true): Promise { + async function updateProject(projectData: Project, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.retrieve.replace('{id}', projectData.id); await patch( endpoint, @@ -130,13 +132,13 @@ export function useProject(): ProjectState { }, response, 'multipart/form-data', - selfprocessError, + selfProcessError, ); } - async function deleteProject(id: string, selfprocessError: boolean = true): Promise { + async function deleteProject(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.retrieve.replace('{id}', id); - await deleteId(endpoint, project, Project.fromJSON, selfprocessError); + await deleteId(endpoint, project, Project.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/structure_check.service.ts b/frontend/src/composables/services/structure_check.service.ts index b50833a8..fa1df7fe 100644 --- a/frontend/src/composables/services/structure_check.service.ts +++ b/frontend/src/composables/services/structure_check.service.ts @@ -7,39 +7,39 @@ interface StructureCheckState { structureChecks: Ref; structureCheck: Ref; - getStructureCheckByID: (id: string, selfprocessError?: boolean) => Promise; - getStructureCheckByProject: (projectId: string, selfprocessError?: boolean) => Promise; + getStructureCheckByID: (id: string, selfProcessError?: boolean) => Promise; + getStructureCheckByProject: (projectId: string, selfProcessError?: boolean) => Promise; createStructureCheck: ( structureCheckData: StructureCheck, projectId: string, - selfprocessError?: boolean, + selfProcessError?: boolean, ) => Promise; setStructureChecks: ( structureChecks: StructureCheck[], projectId: string, - selfprocessError?: boolean, + selfProcessError?: boolean, ) => Promise; - deleteStructureCheck: (id: string, selfprocessError?: boolean) => Promise; + deleteStructureCheck: (id: string, selfProcessError?: boolean) => Promise; } export function useStructureCheck(): StructureCheckState { const structureChecks = ref(null); const structureCheck = ref(null); - async function getStructureCheckByID(id: string, selfprocessError: boolean = true): Promise { + async function getStructureCheckByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.retrieve.replace('{id}', id); - await get(endpoint, structureCheck, StructureCheck.fromJSON, selfprocessError); + await get(endpoint, structureCheck, StructureCheck.fromJSON, selfProcessError); } - async function getStructureCheckByProject(projectId: string, selfprocessError: boolean = true): Promise { + async function getStructureCheckByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); - await getList(endpoint, structureChecks, StructureCheck.fromJSON, selfprocessError); + await getList(endpoint, structureChecks, StructureCheck.fromJSON, selfProcessError); } async function createStructureCheck( structureCheckData: StructureCheck, projectId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); await createToast( @@ -51,22 +51,22 @@ export function useStructureCheck(): StructureCheckState { structureCheck, StructureCheck.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } async function setStructureChecks( structureChecks: StructureCheck[], projectId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.structureChecks.byProject.replace('{projectId}', projectId); - await put(endpoint, structureChecks, undefined, selfprocessError); + await put(endpoint, structureChecks, undefined, selfProcessError); } - async function deleteStructureCheck(id: string, selfprocessError: boolean = true): Promise { + async function deleteStructureCheck(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.structureChecks.retrieve.replace('{id}', id); - await deleteId(endpoint, structureCheck, StructureCheck.fromJSON, selfprocessError); + await deleteId(endpoint, structureCheck, StructureCheck.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/student.service.ts b/frontend/src/composables/services/student.service.ts index 49b80ee0..f12cf6d6 100644 --- a/frontend/src/composables/services/student.service.ts +++ b/frontend/src/composables/services/student.service.ts @@ -8,16 +8,16 @@ interface StudentsState { students: Ref; student: Ref; response: Ref; - getStudentByID: (id: string, init?: boolean, selfprocessError?: boolean) => Promise; - getStudents: (selfprocessError?: boolean) => Promise; - getStudentsByCourse: (courseId: string, selfprocessError?: boolean) => Promise; - getStudentsByGroup: (groupId: string, selfprocessError?: boolean) => Promise; - createStudent: (studentData: Student, selfprocessError?: boolean) => Promise; - deleteStudent: (id: string, selfprocessError?: boolean) => Promise; - studentJoinCourse: (courseId: string, studentId: string, selfprocessError?: boolean) => Promise; - studentLeaveCourse: (courseId: string, studentId: string, selfprocessError?: boolean) => Promise; - studentJoinGroup: (groupId: string, studentId: string, selfprocessError?: boolean) => Promise; - studentLeaveGroup: (groupId: string, studentId: string, selfprocessError?: boolean) => Promise; + getStudentByID: (id: string, init?: boolean, selfProcessError?: boolean) => Promise; + getStudents: (selfProcessError?: boolean) => Promise; + getStudentsByCourse: (courseId: string, selfProcessError?: boolean) => Promise; + getStudentsByGroup: (groupId: string, selfProcessError?: boolean) => Promise; + createStudent: (studentData: Student, selfProcessError?: boolean) => Promise; + deleteStudent: (id: string, selfProcessError?: boolean) => Promise; + studentJoinCourse: (courseId: string, studentId: string, selfProcessError?: boolean) => Promise; + studentLeaveCourse: (courseId: string, studentId: string, selfProcessError?: boolean) => Promise; + studentJoinGroup: (groupId: string, studentId: string, selfProcessError?: boolean) => Promise; + studentLeaveGroup: (groupId: string, studentId: string, selfProcessError?: boolean) => Promise; } export function useStudents(): StudentsState { @@ -26,30 +26,30 @@ export function useStudents(): StudentsState { const student = ref(null); const response = ref(null); - async function getStudentByID(id: string, selfprocessError: boolean = true): Promise { + async function getStudentByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.retrieve.replace('{id}', id); - await get(endpoint, student, Student.fromJSON, selfprocessError); + await get(endpoint, student, Student.fromJSON, selfProcessError); } - async function getStudents(selfprocessError: boolean = true): Promise { + async function getStudents(selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.index; - await getList(endpoint, students, Student.fromJSON, selfprocessError); + await getList(endpoint, students, Student.fromJSON, selfProcessError); } - async function getStudentsByCourse(courseId: string, selfprocessError: boolean = true): Promise { + async function getStudentsByCourse(courseId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); - await getList(endpoint, students, Student.fromJSON, selfprocessError); + await getList(endpoint, students, Student.fromJSON, selfProcessError); } - async function getStudentsByGroup(groupId: string, selfprocessError: boolean = true): Promise { + async function getStudentsByGroup(groupId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); - await getList(endpoint, students, Student.fromJSON, selfprocessError); + await getList(endpoint, students, Student.fromJSON, selfProcessError); } async function studentJoinCourse( courseId: string, studentId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); await create( @@ -58,14 +58,14 @@ export function useStudents(): StudentsState { response, Response.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } async function studentLeaveCourse( courseId: string, studentId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.students.byCourse.replace('{courseId}', courseId); await deleteIdWithData( @@ -73,14 +73,14 @@ export function useStudents(): StudentsState { { student: studentId }, response, Response.fromJSON, - selfprocessError, + selfProcessError, ); } async function studentJoinGroup( groupId: string, studentId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); await create( @@ -89,14 +89,14 @@ export function useStudents(): StudentsState { response, Response.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } async function studentLeaveGroup( groupId: string, studentId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.students.byGroup.replace('{groupId}', groupId); await deleteIdWithData( @@ -104,11 +104,11 @@ export function useStudents(): StudentsState { { student: studentId }, response, Response.fromJSON, - selfprocessError, + selfProcessError, ); } - async function createStudent(studentData: Student, selfprocessError: boolean = true): Promise { + async function createStudent(studentData: Student, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.index; await createToast( @@ -121,13 +121,13 @@ export function useStudents(): StudentsState { student, Student.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } - async function deleteStudent(id: string, selfprocessError: boolean = true): Promise { + async function deleteStudent(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.students.retrieve.replace('{id}', id); - await deleteId(endpoint, student, Student.fromJSON, selfprocessError); + await deleteId(endpoint, student, Student.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/submission.service.ts b/frontend/src/composables/services/submission.service.ts index ae3dd779..2387d0a2 100644 --- a/frontend/src/composables/services/submission.service.ts +++ b/frontend/src/composables/services/submission.service.ts @@ -8,36 +8,36 @@ import { useMessagesStore } from '@/store/messages.store.ts'; interface SubmissionState { submissions: Ref; submission: Ref; - getSubmissionByID: (id: string, selfprocessError?: boolean) => Promise; - getSubmissionByProject: (projectId: string, selfprocessError?: boolean) => Promise; - getSubmissionByGroup: (groupId: string, selfprocessError?: boolean) => Promise; - createSubmission: (submissionData: UnwrapRef, groupId: string, selfprocessError?: boolean) => Promise; - deleteSubmission: (id: string, selfprocessError?: boolean) => Promise; + getSubmissionByID: (id: string, selfProcessError?: boolean) => Promise; + getSubmissionByProject: (projectId: string, selfProcessError?: boolean) => Promise; + getSubmissionByGroup: (groupId: string, selfProcessError?: boolean) => Promise; + createSubmission: (submissionData: UnwrapRef, groupId: string, selfProcessError?: boolean) => Promise; + deleteSubmission: (id: string, selfProcessError?: boolean) => Promise; } export function useSubmission(): SubmissionState { const submissions = ref(null); const submission = ref(null); - async function getSubmissionByID(id: string, selfprocessError: boolean = true): Promise { + async function getSubmissionByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.retrieve.replace('{id}', id); - await get(endpoint, submission, Submission.fromJSON, selfprocessError); + await get(endpoint, submission, Submission.fromJSON, selfProcessError); } - async function getSubmissionByProject(projectId: string, selfprocessError: boolean = true): Promise { + async function getSubmissionByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.byProject.replace('{projectId}', projectId); - await getList(endpoint, submissions, Submission.fromJSON, selfprocessError); + await getList(endpoint, submissions, Submission.fromJSON, selfProcessError); } - async function getSubmissionByGroup(groupId: string, selfprocessError: boolean = true): Promise { + async function getSubmissionByGroup(groupId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.byGroup.replace('{groupId}', groupId); - await getList(endpoint, submissions, Submission.fromJSON, selfprocessError); + await getList(endpoint, submissions, Submission.fromJSON, selfProcessError); } async function createSubmission( uploadedFiles: File[], groupId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const { t } = i18n.global; const { addSuccessMessage } = useMessagesStore(); @@ -48,13 +48,13 @@ export function useSubmission(): SubmissionState { uploadedFiles.forEach((file: File) => { formData.append('files', file); // Gebruik 'files' in plaats van 'files[]' }); - await create(endpoint, formData, submission, Submission.fromJSON, 'multipart/form-data', selfprocessError); + await create(endpoint, formData, submission, Submission.fromJSON, 'multipart/form-data', selfProcessError); addSuccessMessage(t('toasts.messages.success'), t('toasts.messages.submissions.create.success')); } - async function deleteSubmission(id: string, selfprocessError: boolean = true): Promise { + async function deleteSubmission(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.retrieve.replace('{id}', id); - await deleteId(endpoint, submission, Submission.fromJSON, selfprocessError); + await deleteId(endpoint, submission, Submission.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/submission_status.service.ts b/frontend/src/composables/services/submission_status.service.ts index 5e9e2e84..e63cb176 100644 --- a/frontend/src/composables/services/submission_status.service.ts +++ b/frontend/src/composables/services/submission_status.service.ts @@ -5,15 +5,15 @@ import { SubmissionStatus } from '@/types/SubmisionStatus'; interface SubmissionStatusState { submissionStatus: Ref; - getSubmissionStatusByProject: (projectId: string, selfprocessError?: boolean) => Promise; + getSubmissionStatusByProject: (projectId: string, selfProcessError?: boolean) => Promise; } export function useSubmissionStatus(): SubmissionStatusState { const submissionStatus = ref(null); - async function getSubmissionStatusByProject(projectId: string, selfprocessError: boolean = true): Promise { + async function getSubmissionStatusByProject(projectId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.submissions.status.replace('{projectId}', projectId); - await get(endpoint, submissionStatus, SubmissionStatus.fromJSON, selfprocessError); + await get(endpoint, submissionStatus, SubmissionStatus.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/teacher.service.ts b/frontend/src/composables/services/teacher.service.ts index 66101d32..f25583c5 100644 --- a/frontend/src/composables/services/teacher.service.ts +++ b/frontend/src/composables/services/teacher.service.ts @@ -21,14 +21,14 @@ interface TeacherState { teacher: Ref; response: Ref; teacherPagination: Ref | null>; - getTeacherByID: (id: string, init?: boolean, selfprocessError?: boolean) => Promise; - getTeachersByCourse: (courseId: string, selfprocessError?: boolean) => Promise; - getTeachers: (selfprocessError?: boolean) => Promise; - searchTeachers: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; - teacherJoinCourse: (courseId: string, teacherId: string, selfprocessError?: boolean) => Promise; - teacherLeaveCourse: (courseId: string, teacherId: string, selfprocessError?: boolean) => Promise; - createTeacher: (teacherData: Teacher, selfprocessError?: boolean) => Promise; - deleteTeacher: (id: string, selfprocessError?: boolean) => Promise; + getTeacherByID: (id: string, init?: boolean, selfProcessError?: boolean) => Promise; + getTeachersByCourse: (courseId: string, selfProcessError?: boolean) => Promise; + getTeachers: (selfProcessError?: boolean) => Promise; + searchTeachers: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + teacherJoinCourse: (courseId: string, teacherId: string, selfProcessError?: boolean) => Promise; + teacherLeaveCourse: (courseId: string, teacherId: string, selfProcessError?: boolean) => Promise; + createTeacher: (teacherData: Teacher, selfProcessError?: boolean) => Promise; + deleteTeacher: (id: string, selfProcessError?: boolean) => Promise; } export function useTeacher(): TeacherState { @@ -38,26 +38,26 @@ export function useTeacher(): TeacherState { const response = ref(null); const teacherPagination = ref | null>(null); - async function getTeacherByID(id: string, selfprocessError: boolean = true): Promise { + async function getTeacherByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.retrieve.replace('{id}', id); - await get(endpoint, teacher, Teacher.fromJSON, selfprocessError); + await get(endpoint, teacher, Teacher.fromJSON, selfProcessError); } - async function getTeachersByCourse(courseId: string, selfprocessError: boolean = true): Promise { + async function getTeachersByCourse(courseId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); - await getList(endpoint, teachers, Teacher.fromJSON, selfprocessError); + await getList(endpoint, teachers, Teacher.fromJSON, selfProcessError); } - async function getTeachers(selfprocessError: boolean = true): Promise { + async function getTeachers(selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.index; - await getList(endpoint, teachers, Teacher.fromJSON, selfprocessError); + await getList(endpoint, teachers, Teacher.fromJSON, selfProcessError); } async function searchTeachers( filters: Filter, page: number, pageSize: number, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.teachers.search; await getPaginatedList( @@ -67,14 +67,14 @@ export function useTeacher(): TeacherState { pageSize, teacherPagination, Teacher.fromJSON, - selfprocessError, + selfProcessError, ); } async function teacherJoinCourse( courseId: string, teacherId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); await create( @@ -83,14 +83,14 @@ export function useTeacher(): TeacherState { response, Response.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } async function teacherLeaveCourse( courseId: string, teacherId: string, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.teachers.byCourse.replace('{courseId}', courseId); await deleteIdWithData( @@ -98,11 +98,11 @@ export function useTeacher(): TeacherState { { teacher: teacherId }, response, Response.fromJSON, - selfprocessError, + selfProcessError, ); } - async function createTeacher(user: User, selfprocessError: boolean = true): Promise { + async function createTeacher(user: User, selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.index; await createToast( 'teacher', @@ -113,13 +113,13 @@ export function useTeacher(): TeacherState { teacher, Teacher.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } - async function deleteTeacher(id: string, selfprocessError: boolean = true): Promise { + async function deleteTeacher(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.teachers.retrieve.replace('{id}', id); - await deleteId(endpoint, teacher, Teacher.fromJSON, selfprocessError); + await deleteId(endpoint, teacher, Teacher.fromJSON, selfProcessError); } return { diff --git a/frontend/src/composables/services/users.service.ts b/frontend/src/composables/services/users.service.ts index 2d83e126..1f6bfaf9 100644 --- a/frontend/src/composables/services/users.service.ts +++ b/frontend/src/composables/services/users.service.ts @@ -10,11 +10,11 @@ interface userState { pagination: Ref | null>; users: Ref; user: Ref; - getUserByID: (id: string, selfprocessError?: boolean) => Promise; - getUsers: (selfprocessError?: boolean) => Promise; - searchUsers: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise; - createUser: (user_data: User, selfprocessError?: boolean) => Promise; - toggleAdmin: (id: string, is_staff: boolean, selfprocessError?: boolean) => Promise; + getUserByID: (id: string, selfProcessError?: boolean) => Promise; + getUsers: (selfProcessError?: boolean) => Promise; + searchUsers: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise; + createUser: (user_data: User, selfProcessError?: boolean) => Promise; + toggleAdmin: (id: string, is_staff: boolean, selfProcessError?: boolean) => Promise; } export function useUser(): userState { @@ -23,27 +23,27 @@ export function useUser(): userState { const user = ref(null); const response = ref(null); - async function getUserByID(id: string, selfprocessError: boolean = true): Promise { + async function getUserByID(id: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.users.retrieve.replace('{id}', id); - await get(endpoint, user, User.fromJSON, selfprocessError); + await get(endpoint, user, User.fromJSON, selfProcessError); } - async function getUsers(selfprocessError: boolean = true): Promise { + async function getUsers(selfProcessError: boolean = true): Promise { const endpoint = endpoints.users.index; - await getList(endpoint, users, User.fromJSON, selfprocessError); + await getList(endpoint, users, User.fromJSON, selfProcessError); } async function searchUsers( filters: Filter, page: number, pageSize: number, - selfprocessError: boolean = true, + selfProcessError: boolean = true, ): Promise { const endpoint = endpoints.users.search; - await getPaginatedList(endpoint, filters, page, pageSize, pagination, User.fromJSON, selfprocessError); + await getPaginatedList(endpoint, filters, page, pageSize, pagination, User.fromJSON, selfProcessError); } - async function createUser(userData: User, selfprocessError: boolean = true): Promise { + async function createUser(userData: User, selfProcessError: boolean = true): Promise { const endpoint = endpoints.users.index; await createToast( 'user', @@ -58,11 +58,11 @@ export function useUser(): userState { user, User.fromJSON, undefined, - selfprocessError, + selfProcessError, ); } - async function toggleAdmin(id: string, isStaff: boolean, selfprocessError: boolean = true): Promise { + async function toggleAdmin(id: string, isStaff: boolean, selfProcessError: boolean = true): Promise { const endpoint = endpoints.users.admin.replace('{id}', id); await patch( endpoint, @@ -71,7 +71,7 @@ export function useUser(): userState { }, response, undefined, - selfprocessError, + selfProcessError, ); } From 750c5cb3f27e611d192d4cf7200dc43681d504a1 Mon Sep 17 00:00:00 2001 From: EwoutV Date: Thu, 23 May 2024 09:58:13 +0200 Subject: [PATCH 15/17] chore: linting --- frontend/src/composables/services/project.service.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index 97d8a81d..05e2f713 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -1,9 +1,8 @@ -import { Project, ProjectJSON } from '@/types/Project'; +import { Project } from '@/types/Project'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; import { i18n } from '@/config/i18n.ts'; -import axios from 'axios'; -import { create, deleteId, get, getList, patch, processError } from '@/composables/services/helpers.ts'; +import { create, deleteId, get, getList, patch } from '@/composables/services/helpers.ts'; import { type Response } from '@/types/Response.ts'; import { useMessagesStore } from '@/store/messages.store.ts'; From c25e7a6cb4b11bac82ea380e7ee4a7a711810784 Mon Sep 17 00:00:00 2001 From: tyboro2002 Date: Thu, 23 May 2024 10:49:32 +0200 Subject: [PATCH 16/17] chore: fix help --- docs/.vitepress/config.mts | 10 ---------- docs/en/index.md | 11 +---------- docs/en/student-examples.md | 5 +---- docs/nl/index.md | 11 +---------- docs/nl/student-examples.md | 5 +---- 5 files changed, 4 insertions(+), 38 deletions(-) diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index c2f69b82..5eedf8e4 100755 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -24,16 +24,6 @@ export default defineConfig({ // { text: 'Examples', link: '/markdown-examples' } ], - sidebar: [ - { - text: "Algemeen", - items: [ - // { text: 'Markdown Examples', link: '/markdown-examples' }, - // { text: 'Runtime API Examples', link: '/api-examples' } - ], - }, - ], - socialLinks: [ { icon: "github", link: "https://github.com/SELab-2/UGent-7" }, ], diff --git a/docs/en/index.md b/docs/en/index.md index c22a4bae..fac2f489 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -4,8 +4,7 @@ layout: home hero: name: "Ypovoli" - text: "TODO" - tagline: TODO + text: Help pagina actions: - theme: brand text: Student @@ -19,13 +18,5 @@ hero: - theme: brand text: Admin link: /en/admin-examples - -features: - - title: Feature A - details: lorem english - - title: Feature B - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit - - title: Feature C - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit --- diff --git a/docs/en/student-examples.md b/docs/en/student-examples.md index 838cc994..0e555eb3 100644 --- a/docs/en/student-examples.md +++ b/docs/en/student-examples.md @@ -93,9 +93,6 @@ This page describes how to interact with Ypovoli as a student. - Scroll to the "My Courses" section. - Click on the course of the desired project. - Under the "Current Projects" section, you will see all projects for this specific course. -- Option 4: - - Click on "Projects" in the navigation bar. - - You will see an overview of all your projects. ::: info Project card explanation ![project card](../assets/en/project-card.png) @@ -135,4 +132,4 @@ This page describes how to interact with Ypovoli as a student. ## View Previous Submissions Status - Go to the submission page. -- It says there. !!! TODO !!! +- It says there. diff --git a/docs/nl/index.md b/docs/nl/index.md index 9a981c2e..a73bf877 100644 --- a/docs/nl/index.md +++ b/docs/nl/index.md @@ -4,8 +4,7 @@ layout: home hero: name: "Ypovoli" - text: "TODO" - tagline: TODO + text: Help page actions: - theme: brand text: Student @@ -19,13 +18,5 @@ hero: - theme: brand text: Admin link: /nl/admin-examples - -features: - - title: Feature A - details: lorem nederlands - - title: Feature B - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit - - title: Feature C - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit --- diff --git a/docs/nl/student-examples.md b/docs/nl/student-examples.md index 569e2179..4695c23c 100644 --- a/docs/nl/student-examples.md +++ b/docs/nl/student-examples.md @@ -93,9 +93,6 @@ Deze pagina beschrijft hoe u als student met Ypovoli interageert. - Scrol naar de sectie "Mijn vakken". - Druk hier op het vak van het gezochte project. - Onder de sectie "Lopende projecten" ziet u alle projecten voor dit specifieke vak. -- Optie 4: - - Druk in de navigatiebalk op "Projecten". - - U ziet een overzicht van al uw projecten. ::: info Project kaart uitleg @@ -136,4 +133,4 @@ De kaart is als volgt ingedeeld: ## Status vorige indieningen bekijken - Ga naar indien pagina. -- Staat daar bij. !!! TODO !!! +- Staat daar bij. From 11c7d6942ee5bfb23be9dcf87a253402ceebbb50 Mon Sep 17 00:00:00 2001 From: EwoutV Date: Thu, 23 May 2024 11:44:18 +0200 Subject: [PATCH 17/17] chore: merge & toast example --- frontend/src/composables/services/course.service.ts | 8 -------- frontend/src/composables/services/group.service.ts | 2 +- frontend/src/composables/services/project.service.ts | 4 ++-- frontend/src/views/courses/CreateCourseView.vue | 11 +++++++++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/frontend/src/composables/services/course.service.ts b/frontend/src/composables/services/course.service.ts index 89c99247..a6aa061e 100644 --- a/frontend/src/composables/services/course.service.ts +++ b/frontend/src/composables/services/course.service.ts @@ -1,13 +1,11 @@ import { Course } from '@/types/Course.ts'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; -import { i18n } from '@/config/i18n.ts'; import { get, getList, create, patch, deleteId, getPaginatedList } from '@/composables/services/helpers.ts'; import { type Response } from '@/types/Response.ts'; import { type CoursePaginatorResponse } from '@/types/filter/Paginator.ts'; import { type Filter } from '@/types/filter/Filter.ts'; import { type User } from '@/types/users/User.ts'; -import { useMessagesStore } from '@/store/messages.store.ts'; interface CoursesState { pagination: Ref; @@ -95,8 +93,6 @@ export function useCourses(): CoursesState { } async function createCourse(courseData: Course, selfProcessError: boolean = true): Promise { - const { t } = i18n.global; - const { addSuccessMessage } = useMessagesStore(); const endpoint = endpoints.courses.index; await create( endpoint, @@ -114,10 +110,6 @@ export function useCourses(): CoursesState { undefined, selfProcessError, ); - addSuccessMessage( - t('toasts.messages.success'), - t('toasts.messages.courses.create.success', [course.value?.name]), - ); } async function updateCourse(courseData: Course, selfProcessError: boolean = true): Promise { diff --git a/frontend/src/composables/services/group.service.ts b/frontend/src/composables/services/group.service.ts index f2916b92..cf212cff 100644 --- a/frontend/src/composables/services/group.service.ts +++ b/frontend/src/composables/services/group.service.ts @@ -65,7 +65,7 @@ export function useGroup(): GroupState { score: groupData.score, }, response, - selfProcessError + selfProcessError, ); } } diff --git a/frontend/src/composables/services/project.service.ts b/frontend/src/composables/services/project.service.ts index 66c7004c..05e2f713 100644 --- a/frontend/src/composables/services/project.service.ts +++ b/frontend/src/composables/services/project.service.ts @@ -1,4 +1,4 @@ -import { Project, type ProjectJSON } from '@/types/Project'; +import { Project } from '@/types/Project'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; import { i18n } from '@/config/i18n.ts'; @@ -52,7 +52,7 @@ export function useProject(): ProjectState { async function getProjectsByTeacher(teacherId: string, selfProcessError: boolean = true): Promise { const endpoint = endpoints.projects.byTeacher.replace('{teacherId}', teacherId); - await getList(endpoint, projects, Project.fromJSON); + await getList(endpoint, projects, Project.fromJSON, selfProcessError); } async function getProjectsByCourseAndDeadline( diff --git a/frontend/src/views/courses/CreateCourseView.vue b/frontend/src/views/courses/CreateCourseView.vue index 20cf69e4..d78b3e9c 100644 --- a/frontend/src/views/courses/CreateCourseView.vue +++ b/frontend/src/views/courses/CreateCourseView.vue @@ -9,9 +9,11 @@ import { useFaculty } from '@/composables/services/faculty.service.ts'; import { type Course } from '@/types/Course.ts'; import { useCourses } from '@/composables/services/course.service.ts'; import { useRouter } from 'vue-router'; +import { useMessagesStore } from '@/store/messages.store.ts'; /* Composable injections */ const { t } = useI18n(); +const { addSuccessMessage } = useMessagesStore(); const { push } = useRouter(); const { faculties, getFaculties } = useFaculty(); const { createCourse } = useCourses(); @@ -25,8 +27,13 @@ const loading = ref(true); * @param course */ async function saveCourse(course: Course): Promise { - await createCourse(course); - await push({ name: 'dashboard' }); + try { + await createCourse(course); + addSuccessMessage(t('toasts.messages.success'), t('toasts.messages.courses.create.success', [course.name])); + await push({ name: 'dashboard' }); + } catch (error: any) { + // TODO error message + } } /** Load the data */