feat: init activity starting from course

This commit is contained in:
swve 2023-01-22 15:43:42 +01:00
parent a21ccb3626
commit cf7285b6f9
8 changed files with 247 additions and 70 deletions

View 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;
}

View 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;
};