From 2ddb5fa551d06c6d3fa9c031156ba8b67017a42f Mon Sep 17 00:00:00 2001 From: Tybo Verslype <97916632+tyboro2002@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:10:48 +0200 Subject: [PATCH] Update course.service.ts --- .../composables/services/course.service.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frontend/src/composables/services/course.service.ts b/frontend/src/composables/services/course.service.ts index 27e63060..6ae743c8 100644 --- a/frontend/src/composables/services/course.service.ts +++ b/frontend/src/composables/services/course.service.ts @@ -2,6 +2,7 @@ import { Course } from '@/types/Course.ts'; import { type Ref, ref } from 'vue'; import { endpoints } from '@/config/endpoints.ts'; import { get, getList, create, 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'; @@ -16,6 +17,7 @@ interface CoursesState { getCoursesByTeacher: (teacherId: string) => Promise; getCourseByAssistant: (assistantId: string) => Promise; createCourse: (courseData: Course) => Promise; + updateCourse: (courseData: Course) => Promise; cloneCourse: (courseId: string, cloneAssistants: boolean, cloneTeachers: boolean) => Promise; deleteCourse: (id: string) => Promise; } @@ -24,6 +26,7 @@ export function useCourses(): CoursesState { const pagination = ref(null); const courses = ref(null); const course = ref(null); + const response = ref(null); async function getCourseByID(id: string): Promise { const endpoint = endpoints.courses.retrieve.replace('{id}', id); @@ -72,6 +75,22 @@ export function useCourses(): CoursesState { ); } + async function updateCourse(courseData: Course): Promise { + // Endpoint to update is same as retrieve + const endpoint = endpoints.courses.retrieve.replace('{id}', courseData.id); + + await patch( + endpoint, + { + id: courseData.id, + name: courseData.name, + description: courseData.description, + faculty: courseData.faculty?.id, + }, + response, + ); + } + async function cloneCourse(courseId: string, cloneAssistants: boolean, cloneTeachers: boolean): Promise { const endpoint = endpoints.courses.clone.replace('{courseId}', courseId); await create( @@ -103,6 +122,7 @@ export function useCourses(): CoursesState { getCourseByAssistant, createCourse, + updateCourse, cloneCourse, deleteCourse, };