Skip to content

Commit

Permalink
chore: fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
tyboro2002 committed May 21, 2024
1 parent d48691d commit fb1517b
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 43 deletions.
14 changes: 7 additions & 7 deletions frontend/src/composables/services/assistant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function useAssistant(): AssistantState {
filters: Filter,
page: number,
pageSize: number,
selfprocessError: boolean = true
selfprocessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.assistants.search;
await getPaginatedList<Assistant>(
Expand All @@ -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<void> {
const endpoint = endpoints.assistants.byCourse.replace('{courseId}', courseId);
await create<Response>(
Expand All @@ -74,22 +74,22 @@ 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,
);
}

Expand All @@ -103,7 +103,7 @@ export function useAssistant(): AssistantState {
assistant,
Assistant.fromJSON,
undefined,
selfprocessError
selfprocessError,
);
}

Expand Down
45 changes: 36 additions & 9 deletions frontend/src/composables/services/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ interface CoursesState {
getCourseByAssistant: (assistantId: string, 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) => Promise<void>;
cloneCourse: (
courseId: string,
cloneAssistants: boolean,
cloneTeachers: boolean,
selfprocessError?: boolean,
) => Promise<void>;
activateInvitationLink: (courseId: string, linkDuration: number, selfprocessError?: boolean) => Promise<void>;
deleteCourse: (id: string, selfprocessError?: boolean) => Promise<void>;
}
Expand All @@ -39,9 +44,22 @@ export function useCourses(): CoursesState {
await getList<Course>(endpoint, courses, Course.fromJSON, selfprocessError);
}

async function searchCourses(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise<void> {
async function searchCourses(
filters: Filter,
page: number,
pageSize: number,
selfprocessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.courses.search;
await getPaginatedList<Course>(endpoint, filters, page, pageSize, pagination, Course.fromJSON, selfprocessError);
await getPaginatedList<Course>(
endpoint,
filters,
page,
pageSize,
pagination,
Course.fromJSON,
selfprocessError,
);
}

async function getCoursesByStudent(studentId: string, selfprocessError: boolean = true): Promise<void> {
Expand Down Expand Up @@ -75,7 +93,7 @@ export function useCourses(): CoursesState {
course,
Course.fromJSON,
undefined,
selfprocessError
selfprocessError,
);
}

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

Expand All @@ -118,7 +141,11 @@ export function useCourses(): CoursesState {
await deleteId<Course>(endpoint, course, Course.fromJSON, selfprocessError);
}

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

Expand Down
25 changes: 21 additions & 4 deletions frontend/src/composables/services/docker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,34 @@ export function useDockerImages(): DockerImagesState {
await getList<DockerImage>(endpoint, dockerImages, DockerImage.fromJSON, selfprocessError);
}

async function searchDockerImages(filters: Filter, page: number, pageSize: number, selfprocessError: boolean = true): Promise<void> {
async function searchDockerImages(
filters: Filter,
page: number,
pageSize: number,
selfprocessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.dockerImages.search;
await getPaginatedList<DockerImage>(endpoint, filters, page, pageSize, pagination, DockerImage.fromJSON, selfprocessError);
await getPaginatedList<DockerImage>(
endpoint,
filters,
page,
pageSize,
pagination,
DockerImage.fromJSON,
selfprocessError,
);
}

async function patchDockerImage(dockerData: DockerImage, selfprocessError: boolean = true): Promise<void> {
const endpoint = endpoints.dockerImages.patch.replace('{id}', dockerData.id);
await patch(endpoint, { public: dockerData.public }, response, undefined, selfprocessError);
}

async function createDockerImage(dockerData: DockerImage, file: File, selfprocessError: boolean = true): Promise<void> {
async function createDockerImage(
dockerData: DockerImage,
file: File,
selfprocessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.dockerImages.index;
await create<Response>(
endpoint,
Expand All @@ -57,7 +74,7 @@ export function useDockerImages(): DockerImagesState {
response,
Response.fromJSON,
'multipart/form-data',
selfprocessError
selfprocessError,
);
}

Expand Down
8 changes: 6 additions & 2 deletions frontend/src/composables/services/extra_checks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export function useExtraCheck(): ExtraCheckState {
await getList<ExtraCheck>(endpoint, extraChecks, ExtraCheck.fromJSON, selfprocessError);
}

async function addExtraCheck(extraCheckData: ExtraCheck, projectId: string, selfprocessError: boolean = true): Promise<void> {
async function addExtraCheck(
extraCheckData: ExtraCheck,
projectId: string,
selfprocessError: boolean = true,
): Promise<void> {
const endpoint = endpoints.extraChecks.byProject.replace('{projectId}', projectId);
await create<ExtraCheck>(
endpoint,
Expand All @@ -37,7 +41,7 @@ export function useExtraCheck(): ExtraCheckState {
extraCheck,
ExtraCheck.fromJSON,
'multipart/form-data',
selfprocessError
selfprocessError,
);
}

Expand Down
9 changes: 8 additions & 1 deletion frontend/src/composables/services/faculty.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ export function useFaculty(): FacultyState {

async function createFaculty(facultyData: Faculty, selfprocessError: boolean = true): Promise<void> {
const endpoint = endpoints.faculties.index;
await create<Faculty>(endpoint, { id: facultyData.id, name: facultyData.name }, faculty, Faculty.fromJSON, undefined, selfprocessError);
await create<Faculty>(
endpoint,
{ id: facultyData.id, name: facultyData.name },
faculty,
Faculty.fromJSON,
undefined,
selfprocessError,
);
}

async function deleteFaculty(id: string, selfprocessError: boolean = true): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/services/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function useGroup(): GroupState {
group,
Group.fromJSON,
undefined,
selfprocessError
selfprocessError,
);
}

Expand Down
51 changes: 33 additions & 18 deletions frontend/src/composables/services/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ import { type Filter } from '@/types/filter/Filter.ts';
* @param ref
* @param fromJson
*/
export async function get<T>(endpoint: string, ref: Ref<T | null>, fromJson: (data: any) => T, selfprocessError: boolean = true): Promise<void> {
export async function get<T>(
endpoint: string,
ref: Ref<T | null>,
fromJson: (data: any) => T,
selfprocessError: boolean = true,
): Promise<void> {
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
}
}
Expand Down Expand Up @@ -52,10 +57,10 @@ export async function create<T>(
});
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
}
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -100,15 +105,20 @@ export async function patch(
* @param ref
* @param fromJson
*/
export async function deleteId<T>(endpoint: string, ref: Ref<T | null>, fromJson: (data: any) => T, selfprocessError: boolean = true): Promise<void> {
export async function deleteId<T>(
endpoint: string,
ref: Ref<T | null>,
fromJson: (data: any) => T,
selfprocessError: boolean = true,
): Promise<void> {
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
}
}
Expand All @@ -133,10 +143,10 @@ export async function deleteIdWithData<T>(
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
}
}
Expand All @@ -149,16 +159,21 @@ export async function deleteIdWithData<T>(
* @param ref
* @param fromJson
*/
export async function getList<T>(endpoint: string, ref: Ref<T[] | null>, fromJson: (data: any) => T, selfprocessError: boolean = true): Promise<void> {
export async function getList<T>(
endpoint: string,
ref: Ref<T[] | null>,
fromJson: (data: any) => T,
selfprocessError: boolean = true,
): Promise<void> {
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
}
}
Expand Down Expand Up @@ -204,10 +219,10 @@ export async function getPaginatedList<T>(
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
}
}
Expand Down Expand Up @@ -239,7 +254,7 @@ export async function getListMerged<T>(
if(selfprocessError){
processError(error);
console.error(error); // Log the error for debugging
}else{
} else {
throw error; // Re-throw the error to the caller
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/services/project.service.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit fb1517b

Please sign in to comment.