chore: reformat chapters ts

service
This commit is contained in:
swve 2023-02-02 21:34:45 +01:00
parent fb4a8d2882
commit f4466d1932

View file

@ -1,82 +1,41 @@
import { initialData } from "../../components/Drags/data"; import { initialData } from "../../components/Drags/data";
import { getAPIUrl } from "@services/config"; import { getAPIUrl } from "@services/config";
import { RequestBody } from "@services/utils/requests";
/*
This file includes only POST, PUT, DELETE requests
GET requests are called from the frontend using SWR (https://swr.vercel.app/)
*/
//TODO : depreciate this function
export async function getCourseChaptersMetadata(course_id: any) { export async function getCourseChaptersMetadata(course_id: any) {
const HeadersConfig = new Headers({ "Content-Type": "application/json" }); const data: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null))
const requestOptions: any = {
method: "GET",
headers: HeadersConfig,
redirect: "follow",
credentials: "include",
};
const data: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, requestOptions)
.then((result) => result.json()) .then((result) => result.json())
.catch((error) => console.log("error", error)); .catch((error) => console.log("error", error));
console.log("data", data);
return data; return data;
} }
export async function updateChaptersMetadata(course_id: any, data: any) { export async function updateChaptersMetadata(course_id: any, data: any) {
const HeadersConfig = new Headers({ "Content-Type": "application/json" }); const result: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("PUT", data))
const requestOptions: any = {
method: "PUT",
headers: HeadersConfig,
redirect: "follow",
credentials: "include",
body: JSON.stringify(data),
};
const result: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, requestOptions)
.then((result) => result.json()) .then((result) => result.json())
.catch((error) => console.log("error", error)); .catch((error) => console.log("error", error));
console.log("result", result);
return result; return result;
} }
export async function createChapter(data: any, course_id: any) { export async function createChapter(data: any, course_id: any) {
console.log("data", data, course_id); const result: any = await fetch(`${getAPIUrl()}chapters/?course_id=course_${course_id}`, RequestBody("POST", data))
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
const requestOptions: any = {
method: "POST",
headers: HeadersConfig,
redirect: "follow",
credentials: "include",
body: JSON.stringify(data),
};
const result: any = await fetch(`${getAPIUrl()}chapters/?course_id=course_${course_id}`, requestOptions)
.then((result) => result.json()) .then((result) => result.json())
.catch((error) => console.log("error", error)); .catch((error) => console.log("error", error));
console.log("result", result);
return result; return result;
} }
export async function deleteChapter (coursechapter_id: any) { export async function deleteChapter(coursechapter_id: any) {
const HeadersConfig = new Headers({ "Content-Type": "application/json" }); const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, RequestBody("DELETE", null))
const requestOptions: any = {
method: "DELETE",
headers: HeadersConfig,
redirect: "follow",
credentials: "include",
};
const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, requestOptions)
.then((result) => result.json()) .then((result) => result.json())
.catch((error) => console.log("error", error)); .catch((error) => console.log("error", error));
console.log("result", result);
return result; return result;
} }