feat: various improvements

wip: frontend

feat: enable cascade on foreign keys

wip1

wip2

fix chapters issues

wip4
This commit is contained in:
swve 2023-11-29 22:29:48 +01:00
parent 2bf80030d7
commit 187f75e583
71 changed files with 879 additions and 568 deletions

View file

@ -40,7 +40,7 @@ export async function getUserInfo(token: string): Promise<any> {
credentials: "include",
};
return fetch(`${getAPIUrl()}users/profile_metadata`, requestOptions)
return fetch(`${getAPIUrl()}users/profile`, requestOptions)
.then((result) => result.json())
.catch((error) => console.log("error", error));
}

View file

@ -14,19 +14,18 @@ export async function createActivity(data: any, chapter_id: any, org_id: any) {
export async function createFileActivity(file: File, type: string, data: any, chapter_id: any) {
// Send file thumbnail as form data
const formData = new FormData();
formData.append("coursechapter_id", chapter_id);
formData.append("chapter_id", chapter_id);
let org_id = "test";
let endpoint = "";
if (type === "video") {
formData.append("name", data.name);
formData.append("video_file", file);
endpoint = `${getAPIUrl()}activities/video?org_id=${org_id}`;
endpoint = `${getAPIUrl()}activities/video`;
} else if (type === "documentpdf") {
formData.append("pdf_file", file);
formData.append("name", data.name);
endpoint = `${getAPIUrl()}activities/documentpdf?org_id=${org_id}`;
endpoint = `${getAPIUrl()}activities/documentpdf`;
} else {
// Handle other file types here
}
@ -38,7 +37,7 @@ export async function createFileActivity(file: File, type: string, data: any, ch
export async function createExternalVideoActivity(data: any, activity: any, chapter_id: any) {
// add coursechapter_id to data
data.coursechapter_id = chapter_id;
data.chapter_id = chapter_id;
data.activity_id = activity.id;
const result = await fetch(`${getAPIUrl()}activities/external_video?coursechapter_id=${chapter_id}`, RequestBody("POST", data, null));

View file

@ -6,20 +6,20 @@ import { getAPIUrl } from "@services/config/config";
GET requests are called from the frontend using SWR (https://swr.vercel.app/)
*/
export async function startCourse(course_id: string, org_slug: string) {
const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/add_course/${course_id}`, RequestBody("POST", null, null))
export async function startCourse(course_uuid: string, org_slug: string) {
const result: any = await fetch(`${getAPIUrl()}trail/add_course/${course_uuid}`, RequestBody("POST", null, null))
const res = await errorHandling(result);
return res;
}
export async function removeCourse(course_id: string, org_slug: string) {
const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/remove_course/${course_id}`, RequestBody("POST", null, null))
export async function removeCourse(course_uuid: string, org_slug: string) {
const result: any = await fetch(`${getAPIUrl()}trail/remove_course/${course_uuid}`, RequestBody("DELETE", null, null))
const res = await errorHandling(result);
return res;
}
export async function markActivityAsComplete(org_slug: string, course_id: string, activity_id: string) {
const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/add_activity/course_id/${course_id}/activity_id/${activity_id}`, RequestBody("POST", null, null))
export async function markActivityAsComplete(org_slug: string, course_uuid: string, activity_id: string) {
const result: any = await fetch(`${getAPIUrl()}trail/add_activity/${activity_id}`, RequestBody("POST", null, null))
const res = await errorHandling(result);
return res;
}

View file

@ -7,16 +7,14 @@ import { RequestBody, RequestBodyWithAuthHeader, errorHandling } from "@services
*/
//TODO : depreciate this function
export async function getCourseChaptersMetadata(course_id: any, next: any) {
const result = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null, next));
export async function getCourseChaptersMetadata(course_uuid: any, next: any) {
const result = await fetch(`${getAPIUrl()}chapters/meta/course_${course_uuid}`, RequestBody("GET", null, next));
const res = await errorHandling(result);
return res;
}
export async function updateChaptersMetadata(course_id: any, data: any) {
const result: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("PUT", data, null));
export async function updateChaptersMetadata(course_uuid: any, data: any) {
const result: any = await fetch(`${getAPIUrl()}chapters/course/course_${course_uuid}/order`, RequestBody("PUT", data, null));
const res = await errorHandling(result);
return res;
}
@ -27,8 +25,8 @@ export async function updateChapter(coursechapter_id: any, data: any) {
return res;
}
export async function createChapter(data: any, course_id: any) {
const result: any = await fetch(`${getAPIUrl()}chapters/?course_id=course_${course_id}`, RequestBody("POST", data, null));
export async function createChapter(data: any) {
const result: any = await fetch(`${getAPIUrl()}chapters/`, RequestBody("POST", data, null));
const res = await errorHandling(result);
return res;

View file

@ -6,8 +6,8 @@ import { RequestBody, RequestBodyWithAuthHeader, errorHandling } from "@services
GET requests are called from the frontend using SWR (https://swr.vercel.app/)
*/
export async function deleteCollection(collection_id: any) {
const result: any = await fetch(`${getAPIUrl()}collections/${collection_id}`, RequestBody("DELETE", null, null));
export async function deleteCollection(collection_uuid: any) {
const result: any = await fetch(`${getAPIUrl()}collections/${collection_uuid}`, RequestBody("DELETE", null, null));
const res = await errorHandling(result);
return res;
}
@ -20,14 +20,14 @@ export async function createCollection(collection: any) {
}
// Get a colletion by id
export async function getCollectionById(collection_id: any) {
const result: any = await fetch(`${getAPIUrl()}collections/${collection_id}`, { next: { revalidate: 10 } });
export async function getCollectionById(collection_uuid: any) {
const result: any = await fetch(`${getAPIUrl()}collections/${collection_uuid}`, { next: { revalidate: 10 } });
const res = await errorHandling(result);
return res;
}
export async function getCollectionByIdWithAuthHeader(collection_id: any, access_token: string, next: any) {
const result: any = await fetch(`${getAPIUrl()}collections/collection_${collection_id}`, RequestBodyWithAuthHeader("GET", null, next, access_token));
export async function getCollectionByIdWithAuthHeader(collection_uuid: any, access_token: string, next: any) {
const result: any = await fetch(`${getAPIUrl()}collections/collection_${collection_uuid}`, RequestBodyWithAuthHeader("GET", null, next, access_token));
const res = await errorHandling(result);
return res;
}
@ -41,7 +41,7 @@ export async function getOrgCollections() {
}
export async function getOrgCollectionsWithAuthHeader(org_id: string, access_token: string, next: any) {
const result: any = await fetch(`${getAPIUrl()}collections/org_id/${org_id}/page/1/limit/10`, RequestBodyWithAuthHeader("GET", null, next, access_token));
const result: any = await fetch(`${getAPIUrl()}collections/org/${org_id}/page/1/limit/10`, RequestBodyWithAuthHeader("GET", null, next, access_token));
const res = await errorHandling(result);
return res;
}

View file

@ -18,20 +18,20 @@ export async function getOrgCoursesWithAuthHeader(org_id: number, next: any, acc
return res;
}
export async function getCourseMetadataWithAuthHeader(course_id: any, next: any, access_token: string) {
const result = await fetch(`${getAPIUrl()}courses/meta/course_${course_id}`, RequestBodyWithAuthHeader("GET", null, next, access_token));
export async function getCourseMetadataWithAuthHeader(course_uuid: any, next: any, access_token: string) {
const result = await fetch(`${getAPIUrl()}courses/course_${course_uuid}/meta`, RequestBodyWithAuthHeader("GET", null, next, access_token));
const res = await errorHandling(result);
return res;
}
export async function updateCourse(course_id: any, data: any) {
const result: any = await fetch(`${getAPIUrl()}courses/course_${course_id}`, RequestBody("PUT", data, null));
export async function updateCourse(course_uuid: any, data: any) {
const result: any = await fetch(`${getAPIUrl()}courses/course_${course_uuid}`, RequestBody("PUT", data, null));
const res = await errorHandling(result);
return res;
}
export async function getCourse(course_id: string, next: any) {
const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("GET", null, next));
export async function getCourse(course_uuid: string, next: any) {
const result: any = await fetch(`${getAPIUrl()}courses/${course_uuid}`, RequestBody("GET", null, next));
const res = await errorHandling(result);
return res;
}
@ -39,19 +39,21 @@ export async function getCourse(course_id: string, next: any) {
export async function createNewCourse(org_id: string, course_body: any, thumbnail: any) {
// Send file thumbnail as form data
const formData = new FormData();
formData.append("thumbnail", thumbnail);
formData.append("name", course_body.name);
formData.append("description", course_body.description);
formData.append("mini_description", "course_body.mini_description");
formData.append("public", "true");
formData.append("public", course_body.visibility);
formData.append("learnings", course_body.tags);
formData.append("tags", course_body.tags);
formData.append("about", course_body.description);
formData.append("thumbnail", thumbnail);
const result = await fetch(`${getAPIUrl()}courses/?org_id=${org_id}`, RequestBodyForm("POST", formData, null));
const res = await errorHandling(result);
return res;
}
export async function deleteCourseFromBackend(course_id: any) {
const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("DELETE", null, null));
export async function deleteCourseFromBackend(course_uuid: any) {
const result: any = await fetch(`${getAPIUrl()}courses/${course_uuid}`, RequestBody("DELETE", null, null));
const res = await errorHandling(result);
return res;
}