mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-28 23:39:15 +02:00
98 lines
2.5 KiB
TypeScript
98 lines
2.5 KiB
TypeScript
// function to fetch course data from the API
|
|
|
|
import { Module } from "../model/module.ts";
|
|
|
|
export async function fetchCourse(): Promise<string[]> {
|
|
const courses: string[] = [];
|
|
await fetch("/api/courses")
|
|
.then((response) => {
|
|
//check if response type is json
|
|
const contentType = response.headers.get("content-type");
|
|
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
return response.json();
|
|
} else {
|
|
return [];
|
|
}
|
|
})
|
|
.then((coursesResponse) => {
|
|
coursesResponse.forEach((course: string) => courses.push(course));
|
|
});
|
|
return courses;
|
|
}
|
|
|
|
export async function fetchCourseBySemester(
|
|
semester: string,
|
|
): Promise<string[]> {
|
|
const courses: string[] = [];
|
|
await fetch("/api/courses/events?semester=" + semester)
|
|
.then((response) => {
|
|
//check if response type is json
|
|
const contentType = response.headers.get("content-type");
|
|
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
return response.json();
|
|
} else {
|
|
return [];
|
|
}
|
|
})
|
|
.then((coursesResponse) => {
|
|
coursesResponse?.forEach((course: string) => courses.push(course));
|
|
});
|
|
return courses;
|
|
}
|
|
|
|
export async function fetchModulesByCourseAndSemester(
|
|
course: string,
|
|
semester: string,
|
|
): Promise<Module[]> {
|
|
const modules: Module[] = [];
|
|
await fetch("/api/course/modules?course=" + course + "&semester=" + semester)
|
|
.then((response) => {
|
|
return response.json();
|
|
})
|
|
.then((modulesResponse) => {
|
|
modulesResponse.forEach((module: Module) =>
|
|
modules.push(
|
|
new Module(
|
|
module.uuid,
|
|
module.name,
|
|
course,
|
|
module.eventType,
|
|
module.name,
|
|
module.prof,
|
|
semester,
|
|
false,
|
|
module.events,
|
|
),
|
|
),
|
|
);
|
|
});
|
|
return modules;
|
|
}
|
|
|
|
export async function fetchAllModules(): Promise<Module[]> {
|
|
const modules: Module[] = [];
|
|
await fetch("/api/modules")
|
|
.then((response) => {
|
|
return response.json() as Promise<Module[]>;
|
|
})
|
|
.then((responseModules: Module[]) => {
|
|
responseModules.forEach((module: Module) => {
|
|
modules.push(
|
|
new Module(
|
|
module.uuid,
|
|
module.name,
|
|
module.course,
|
|
module.eventType,
|
|
module.name,
|
|
module.prof,
|
|
module.semester,
|
|
false,
|
|
module.events,
|
|
),
|
|
);
|
|
});
|
|
});
|
|
|
|
return modules;
|
|
}
|