mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
chore: use RequestBody for everything else
This commit is contained in:
parent
ab96e34029
commit
6e037538af
5 changed files with 23 additions and 155 deletions
|
|
@ -1,23 +1,13 @@
|
|||
import { getAPIUrl } from "@services/config";
|
||||
import { RequestBody, RequestBodyForm } from "@services/utils/requests";
|
||||
|
||||
export async function createLecture(data: any, chapter_id: any) {
|
||||
data.content = {};
|
||||
console.log("data", data, chapter_id);
|
||||
|
||||
// remove chapter_id from data
|
||||
delete data.chapterId;
|
||||
|
||||
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()}lectures/?coursechapter_id=${chapter_id}`, requestOptions)
|
||||
const result: any = await fetch(`${getAPIUrl()}lectures/?coursechapter_id=${chapter_id}`, RequestBody("POST", data))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
|
||||
|
|
@ -27,15 +17,9 @@ export async function createLecture(data: any, chapter_id: any) {
|
|||
}
|
||||
|
||||
export async function createFileLecture(file: File, type: string, data: any, chapter_id: any) {
|
||||
|
||||
|
||||
const HeadersConfig = new Headers();
|
||||
|
||||
// Send file thumbnail as form data
|
||||
const formData = new FormData();
|
||||
formData.append("coursechapter_id", chapter_id);
|
||||
console.log("type" , type);
|
||||
|
||||
|
||||
let endpoint = `${getAPIUrl()}lectures/video`;
|
||||
|
||||
|
|
@ -45,36 +29,17 @@ export async function createFileLecture(file: File, type: string, data: any, cha
|
|||
endpoint = `${getAPIUrl()}lectures/video`;
|
||||
}
|
||||
|
||||
console.log();
|
||||
|
||||
|
||||
const requestOptions: any = {
|
||||
method: "POST",
|
||||
headers: HeadersConfig,
|
||||
redirect: "follow",
|
||||
credentials: "include",
|
||||
body: formData,
|
||||
};
|
||||
|
||||
const result: any = await fetch(endpoint, requestOptions)
|
||||
const result: any = await fetch(endpoint, RequestBodyForm("POST", formData))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
|
||||
|
||||
|
||||
console.log("result", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getLecture(lecture_id: any) {
|
||||
const requestOptions: any = {
|
||||
method: "GET",
|
||||
redirect: "follow",
|
||||
credentials: "include",
|
||||
};
|
||||
|
||||
const result: any = await fetch(`${getAPIUrl()}lectures/${lecture_id}`, requestOptions)
|
||||
const result: any = await fetch(`${getAPIUrl()}lectures/${lecture_id}`, RequestBody("GET", null))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
|
||||
|
|
@ -82,17 +47,7 @@ export async function getLecture(lecture_id: any) {
|
|||
}
|
||||
|
||||
export async function updateLecture(data: any, lecture_id: 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()}lectures/${lecture_id}`, requestOptions)
|
||||
const result: any = await fetch(`${getAPIUrl()}lectures/${lecture_id}`, RequestBody("PUT", data))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue