Skip to content

Commit

Permalink
Update course.service.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tyboro2002 authored Apr 18, 2024
1 parent 081e7f0 commit 2ddb5fa
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions frontend/src/composables/services/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -16,6 +17,7 @@ interface CoursesState {
getCoursesByTeacher: (teacherId: string) => Promise<void>;
getCourseByAssistant: (assistantId: string) => Promise<void>;
createCourse: (courseData: Course) => Promise<void>;
updateCourse: (courseData: Course) => Promise<void>;
cloneCourse: (courseId: string, cloneAssistants: boolean, cloneTeachers: boolean) => Promise<void>;
deleteCourse: (id: string) => Promise<void>;
}
Expand All @@ -24,6 +26,7 @@ export function useCourses(): CoursesState {
const pagination = ref<CoursePaginatorResponse | null>(null);
const courses = ref<Course[] | null>(null);
const course = ref<Course | null>(null);
const response = ref<Response | null>(null);

async function getCourseByID(id: string): Promise<void> {
const endpoint = endpoints.courses.retrieve.replace('{id}', id);
Expand Down Expand Up @@ -72,6 +75,22 @@ export function useCourses(): CoursesState {
);
}

async function updateCourse(courseData: Course): Promise<void> {
// 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<void> {
const endpoint = endpoints.courses.clone.replace('{courseId}', courseId);
await create<Course>(
Expand Down Expand Up @@ -103,6 +122,7 @@ export function useCourses(): CoursesState {
getCourseByAssistant,

createCourse,
updateCourse,
cloneCourse,
deleteCourse,
};
Expand Down

0 comments on commit 2ddb5fa

Please sign in to comment.