mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init activity starting from course
This commit is contained in:
parent
a21ccb3626
commit
cf7285b6f9
8 changed files with 247 additions and 70 deletions
24
front/services/courses/activity.ts
Normal file
24
front/services/courses/activity.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { RequestBody } from "@services/utils/requests";
|
||||
import { getAPIUrl } from "../config";
|
||||
|
||||
/*
|
||||
This file includes only POST, PUT, DELETE requests
|
||||
GET requests are called from the frontend using SWR (https://swr.vercel.app/)
|
||||
*/
|
||||
|
||||
export async function createActivity(course_id: string) {
|
||||
let data = {
|
||||
course_id: course_id,
|
||||
};
|
||||
const result: any = await fetch(`${getAPIUrl()}activity/start`, RequestBody("POST", data))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function closeActivity(org_id: string, activity_id: string) {
|
||||
const result: any = await fetch(`${getAPIUrl()}activity/${org_id}/close_activity/${activity_id}"`, RequestBody("PATCH", null))
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
return result;
|
||||
}
|
||||
13
front/services/utils/requests.ts
Normal file
13
front/services/utils/requests.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export const RequestBody = (method: string, data: any) => {
|
||||
let HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||
let options: any = {
|
||||
method: method,
|
||||
headers: HeadersConfig,
|
||||
redirect: "follow",
|
||||
credentials: "include",
|
||||
};
|
||||
if (data) {
|
||||
options.body = JSON.stringify(data);
|
||||
}
|
||||
return options;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue