Skip to content

Commit

Permalink
fix: project service
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed May 23, 2024
1 parent 1e67c9d commit 4a7148c
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 280 deletions.
24 changes: 12 additions & 12 deletions frontend/src/composables/services/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ import { User } from '@/types/users/User.ts';
interface AdminState {
admins: Ref<User[] | null>;
admin: Ref<User | null>;
getAdminByID: (id: string, selfprocessError?: boolean) => Promise<void>;
getAdmins: (selfprocessError?: boolean) => Promise<void>;
createAdmin: (adminData: User, selfprocessError?: boolean) => Promise<void>;
deleteAdmin: (id: string, selfprocessError?: boolean) => Promise<void>;
getAdminByID: (id: string, selfProcessError?: boolean) => Promise<void>;
getAdmins: (selfProcessError?: boolean) => Promise<void>;
createAdmin: (adminData: User, selfProcessError?: boolean) => Promise<void>;
deleteAdmin: (id: string, selfProcessError?: boolean) => Promise<void>;
}

export function useAdmin(): AdminState {
const admins = ref<User[] | null>(null);
const admin = ref<User | null>(null);

async function getAdminByID(id: string, selfprocessError: boolean = true): Promise<void> {
async function getAdminByID(id: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.admins.retrieve.replace('{id}', id);
await get<User>(endpoint, admin, User.fromJSON, selfprocessError);
await get<User>(endpoint, admin, User.fromJSON, selfProcessError);
}

async function getAdmins(selfprocessError: boolean = true): Promise<void> {
async function getAdmins(selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.admins.index;
await getList<User>(endpoint, admins, User.fromJSON, selfprocessError);
await getList<User>(endpoint, admins, User.fromJSON, selfProcessError);
}

async function createAdmin(user: User, selfprocessError: boolean = true): Promise<void> {
async function createAdmin(user: User, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.admins.index;
await createToast<User>(
'admin',
Expand All @@ -37,13 +37,13 @@ export function useAdmin(): AdminState {
admin,
User.fromJSON,
undefined,
selfprocessError,
selfProcessError,
);
}

async function deleteAdmin(id: string, selfprocessError: boolean = true): Promise<void> {
async function deleteAdmin(id: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.admins.retrieve.replace('{id}', id);
await deleteId<User>(endpoint, admin, User.fromJSON, selfprocessError);
await deleteId<User>(endpoint, admin, User.fromJSON, selfProcessError);
}

return {
Expand Down
48 changes: 24 additions & 24 deletions frontend/src/composables/services/assistant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ interface AssistantState {
assistant: Ref<Assistant | null>;
response: Ref<Response | null>;
assistantPagination: Ref<PaginatorResponse<Assistant> | null>;
getAssistantByID: (id: string, init?: boolean, selfprocessError?: boolean) => Promise<void>;
getAssistantsByCourse: (courseId: string, selfprocessError?: boolean) => Promise<void>;
getAssistants: (selfprocessError?: boolean) => Promise<void>;
searchAssistants: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise<void>;
assistantJoinCourse: (courseId: string, assistantId: string, selfprocessError?: boolean) => Promise<void>;
assistantLeaveCourse: (courseId: string, assistantId: string, selfprocessError?: boolean) => Promise<void>;
createAssistant: (assistantData: Assistant, selfprocessError?: boolean) => Promise<void>;
deleteAssistant: (id: string, selfprocessError?: boolean) => Promise<void>;
getAssistantByID: (id: string, init?: boolean, selfProcessError?: boolean) => Promise<void>;
getAssistantsByCourse: (courseId: string, selfProcessError?: boolean) => Promise<void>;
getAssistants: (selfProcessError?: boolean) => Promise<void>;
searchAssistants: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise<void>;
assistantJoinCourse: (courseId: string, assistantId: string, selfProcessError?: boolean) => Promise<void>;
assistantLeaveCourse: (courseId: string, assistantId: string, selfProcessError?: boolean) => Promise<void>;
createAssistant: (assistantData: Assistant, selfProcessError?: boolean) => Promise<void>;
deleteAssistant: (id: string, selfProcessError?: boolean) => Promise<void>;
}

export function useAssistant(): AssistantState {
Expand All @@ -37,26 +37,26 @@ export function useAssistant(): AssistantState {
const response = ref<Response | null>(null);
const assistantPagination = ref<PaginatorResponse<Assistant> | null>(null);

async function getAssistantByID(id: string, selfprocessError: boolean = true): Promise<void> {
async function getAssistantByID(id: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.assistants.retrieve.replace('{id}', id);
await get<Assistant>(endpoint, assistant, Assistant.fromJSON, selfprocessError);
await get<Assistant>(endpoint, assistant, Assistant.fromJSON, selfProcessError);
}

async function getAssistantsByCourse(courseId: string, selfprocessError: boolean = true): Promise<void> {
async function getAssistantsByCourse(courseId: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId);
await getList<Assistant>(endpoint, assistants, Assistant.fromJSON, selfprocessError);
await getList<Assistant>(endpoint, assistants, Assistant.fromJSON, selfProcessError);
}

async function getAssistants(selfprocessError: boolean = true): Promise<void> {
async function getAssistants(selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.assistants.index;
await getList<Assistant>(endpoint, assistants, Assistant.fromJSON, selfprocessError);
await getList<Assistant>(endpoint, assistants, Assistant.fromJSON, selfProcessError);
}

async function searchAssistants(
filters: Filter,
page: number,
pageSize: number,
selfprocessError: boolean = true,
selfProcessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.assistants.search;
await getPaginatedList<Assistant>(
Expand All @@ -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<void> {
const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId);
await create<Response>(
Expand All @@ -82,26 +82,26 @@ export function useAssistant(): AssistantState {
response,
Response.fromJSON,
undefined,
selfprocessError,
selfProcessError,
);
}

async function assistantLeaveCourse(
courseId: string,
assistantId: string,
selfprocessError: boolean = true,
selfProcessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId);
await deleteIdWithData<Response>(
endpoint,
{ assistant: assistantId },
response,
Response.fromJSON,
selfprocessError,
selfProcessError,
);
}

async function createAssistant(user: User, selfprocessError: boolean = true): Promise<void> {
async function createAssistant(user: User, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.assistants.index;
await createToast<Assistant>(
'assistant',
Expand All @@ -112,13 +112,13 @@ export function useAssistant(): AssistantState {
assistant,
Assistant.fromJSON,
undefined,
selfprocessError,
selfProcessError,
);
}

async function deleteAssistant(id: string, selfprocessError: boolean = true): Promise<void> {
async function deleteAssistant(id: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.assistants.retrieve.replace('{id}', id);
await deleteId<Assistant>(endpoint, assistant, Assistant.fromJSON, selfprocessError);
await deleteId<Assistant>(endpoint, assistant, Assistant.fromJSON, selfProcessError);
}

return {
Expand Down
76 changes: 38 additions & 38 deletions frontend/src/composables/services/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ interface CoursesState {
courses: Ref<Course[] | null>;
course: Ref<Course | null>;

getCourseByID: (id: string, selfprocessError?: boolean) => Promise<void>;
getCourses: (selfprocessError?: boolean) => Promise<void>;
searchCourses: (filters: Filter, page: number, pageSize: number, selfprocessError?: boolean) => Promise<void>;
getCoursesByStudent: (studentId: string, selfprocessError?: boolean) => Promise<void>;
getCoursesByTeacher: (teacherId: string, selfprocessError?: boolean) => Promise<void>;
getCourseByAssistant: (assistantId: string, selfprocessError?: boolean) => Promise<void>;
getCoursesByUser: (user: User, selfprocessError?: boolean) => Promise<void>;
createCourse: (courseData: Course, selfprocessError?: boolean) => Promise<void>;
updateCourse: (courseData: Course, selfprocessError?: boolean) => Promise<void>;
getCourseByID: (id: string, selfProcessError?: boolean) => Promise<void>;
getCourses: (selfProcessError?: boolean) => Promise<void>;
searchCourses: (filters: Filter, page: number, pageSize: number, selfProcessError?: boolean) => Promise<void>;
getCoursesByStudent: (studentId: string, selfProcessError?: boolean) => Promise<void>;
getCoursesByTeacher: (teacherId: string, selfProcessError?: boolean) => Promise<void>;
getCourseByAssistant: (assistantId: string, selfProcessError?: boolean) => Promise<void>;
getCoursesByUser: (user: User, selfProcessError?: boolean) => Promise<void>;
createCourse: (courseData: Course, selfProcessError?: boolean) => Promise<void>;
updateCourse: (courseData: Course, selfProcessError?: boolean) => Promise<void>;
cloneCourse: (
courseId: string,
cloneAssistants: boolean,
cloneTeachers: boolean,
selfprocessError?: boolean,
selfProcessError?: boolean,
) => Promise<void>;
activateInvitationLink: (courseId: string, linkDuration: number, selfprocessError?: boolean) => Promise<void>;
deleteCourse: (id: string, selfprocessError?: boolean) => Promise<void>;
activateInvitationLink: (courseId: string, linkDuration: number, selfProcessError?: boolean) => Promise<void>;
deleteCourse: (id: string, selfProcessError?: boolean) => Promise<void>;
}

export function useCourses(): CoursesState {
Expand All @@ -39,21 +39,21 @@ export function useCourses(): CoursesState {
const course = ref<Course | null>(null);
const response = ref<Response | null>(null);

async function getCourseByID(id: string, selfprocessError: boolean = true): Promise<void> {
async function getCourseByID(id: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.courses.retrieve.replace('{id}', id);
await get<Course>(endpoint, course, Course.fromJSON, selfprocessError);
await get<Course>(endpoint, course, Course.fromJSON, selfProcessError);
}

async function getCourses(selfprocessError: boolean = true): Promise<void> {
async function getCourses(selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.courses.index;
await getList<Course>(endpoint, courses, Course.fromJSON, selfprocessError);
await getList<Course>(endpoint, courses, Course.fromJSON, selfProcessError);
}

async function searchCourses(
filters: Filter,
page: number,
pageSize: number,
selfprocessError: boolean = true,
selfProcessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.courses.search;
await getPaginatedList<Course>(
Expand All @@ -63,38 +63,38 @@ export function useCourses(): CoursesState {
pageSize,
pagination,
Course.fromJSON,
selfprocessError,
selfProcessError,
);
}

async function getCoursesByStudent(studentId: string, selfprocessError: boolean = true): Promise<void> {
async function getCoursesByStudent(studentId: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.courses.byStudent.replace('{studentId}', studentId);
await getList<Course>(endpoint, courses, Course.fromJSON, selfprocessError);
await getList<Course>(endpoint, courses, Course.fromJSON, selfProcessError);
}

async function getCoursesByTeacher(teacherId: string, selfprocessError: boolean = true): Promise<void> {
async function getCoursesByTeacher(teacherId: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.courses.byTeacher.replace('{teacherId}', teacherId);
await getList<Course>(endpoint, courses, Course.fromJSON, selfprocessError);
await getList<Course>(endpoint, courses, Course.fromJSON, selfProcessError);
}

async function getCourseByAssistant(assistantId: string, selfprocessError: boolean = true): Promise<void> {
async function getCourseByAssistant(assistantId: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.courses.byAssistant.replace('{assistantId}', assistantId);
await getList<Course>(endpoint, courses, Course.fromJSON, selfprocessError);
await getList<Course>(endpoint, courses, Course.fromJSON, selfProcessError);
}

async function getCoursesByUser(user: User, selfprocessError: boolean = true): Promise<void> {
async function getCoursesByUser(user: User, selfProcessError: boolean = true): Promise<void> {
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<void> {
async function createCourse(courseData: Course, selfProcessError: boolean = true): Promise<void> {
const { t } = i18n.global;
const { addSuccessMessage } = useMessagesStore();
const endpoint = endpoints.courses.index;
Expand All @@ -112,15 +112,15 @@ export function useCourses(): CoursesState {
course,
Course.fromJSON,
undefined,
selfprocessError,
selfProcessError,
);
addSuccessMessage(
t('toasts.messages.success'),
t('toasts.messages.courses.create.success', [course.value?.name]),
);
}

async function updateCourse(courseData: Course, selfprocessError: boolean = true): Promise<void> {
async function updateCourse(courseData: Course, selfProcessError: boolean = true): Promise<void> {
// Endpoint to update is same as retrieve
const endpoint = endpoints.courses.retrieve.replace('{id}', courseData.id);

Expand All @@ -136,15 +136,15 @@ export function useCourses(): CoursesState {
},
response,
undefined,
selfprocessError,
selfProcessError,
);
}

async function cloneCourse(
courseId: string,
cloneAssistants: boolean,
cloneTeachers: boolean,
selfprocessError: boolean = true,
selfProcessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.courses.clone.replace('{courseId}', courseId);
await create<Course>(
Expand All @@ -156,19 +156,19 @@ export function useCourses(): CoursesState {
course,
Course.fromJSON,
undefined,
selfprocessError,
selfProcessError,
);
}

async function deleteCourse(id: string, selfprocessError: boolean = true): Promise<void> {
async function deleteCourse(id: string, selfProcessError: boolean = true): Promise<void> {
const endpoint = endpoints.courses.retrieve.replace('{id}', id);
await deleteId<Course>(endpoint, course, Course.fromJSON, selfprocessError);
await deleteId<Course>(endpoint, course, Course.fromJSON, selfProcessError);
}

async function activateInvitationLink(
courseId: string,
linkDuration: number,
selfprocessError: boolean = true,
selfProcessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.courses.invitationLink.replace('{courseId}', courseId);
await patch(
Expand All @@ -178,7 +178,7 @@ export function useCourses(): CoursesState {
},
response,
undefined,
selfprocessError,
selfProcessError,
);
}

Expand Down
Loading

0 comments on commit 4a7148c

Please sign in to comment.