mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-18 20:09:25 +00:00
chore: reformat chapters ts
service
This commit is contained in:
parent
fb4a8d2882
commit
f4466d1932
1 changed files with 13 additions and 54 deletions
|
|
@ -1,82 +1,41 @@
|
|||
import { initialData } from "../../components/Drags/data";
|
||||
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) {
|
||||
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||
|
||||
const requestOptions: any = {
|
||||
method: "GET",
|
||||
headers: HeadersConfig,
|
||||
redirect: "follow",
|
||||
credentials: "include",
|
||||
};
|
||||
|
||||
const data: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, requestOptions)
|
||||
const data: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
|
||||
console.log("data", data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function updateChaptersMetadata(course_id: any, data: any) {
|
||||
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||
|
||||
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)
|
||||
const result: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("PUT", data))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
|
||||
console.log("result", result);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function createChapter(data: any, course_id: any) {
|
||||
console.log("data", data, course_id);
|
||||
|
||||
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)
|
||||
const result: any = await fetch(`${getAPIUrl()}chapters/?course_id=course_${course_id}`, RequestBody("POST", data))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
|
||||
console.log("result", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteChapter (coursechapter_id: any) {
|
||||
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||
|
||||
const requestOptions: any = {
|
||||
method: "DELETE",
|
||||
headers: HeadersConfig,
|
||||
redirect: "follow",
|
||||
credentials: "include",
|
||||
};
|
||||
|
||||
const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, requestOptions)
|
||||
export async function deleteChapter(coursechapter_id: any) {
|
||||
const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, RequestBody("DELETE", null))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
|
||||
console.log("result", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue