feat: course creation/del + file upload

This commit is contained in:
swve 2022-10-15 16:55:19 +02:00
parent 9a8e4e4492
commit c838b7e9cd
9 changed files with 151 additions and 21 deletions

View file

@ -15,7 +15,7 @@ export async function getOrgCourses(org_id: number) {
.catch((error) => console.log("error", error));
}
export async function getCourse(org_id: any, course_id: any) {
export async function getCourse(course_id: any) {
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
const requestOptions: any = {
@ -30,3 +30,42 @@ export async function getCourse(org_id: any, course_id: any) {
.then((result) => result.json())
.catch((error) => console.log("error", error));
}
export async function createNewCourse(org_id: string, course_body: any, thumbnail: any) {
const HeadersConfig = new Headers();
// Send file thumbnail as form data
const formData = new FormData();
formData.append("thumbnail", thumbnail);
formData.append("name", course_body.name);
formData.append("description", course_body.description);
formData.append("mini_description", "course_body.mini_description");
formData.append("public", "true");
const requestOptions: any = {
method: "POST",
headers: HeadersConfig,
redirect: "follow",
credentials: "include",
body: formData,
};
return fetch(`${getAPIUrl()}courses/?org_id=${org_id}`, requestOptions)
.then((result) => result.json())
.catch((error) => console.log("error", error));
}
export async function deleteCourseFromBackend(course_id: any) {
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
const requestOptions: any = {
method: "DELETE",
headers: HeadersConfig,
redirect: "follow",
credentials: "include",
};
return fetch(`${getAPIUrl()}courses/${course_id}`, requestOptions)
.then((result) => result.json())
.catch((error) => console.log("error", error));
}