diff --git a/front/services/blocks/Image/images.ts b/front/services/blocks/Image/images.ts index 0429b6dd..8a1ab1c2 100644 --- a/front/services/blocks/Image/images.ts +++ b/front/services/blocks/Image/images.ts @@ -7,14 +7,14 @@ export async function uploadNewImageFile(file: any, activity_id: string) { formData.append("file_object", file); formData.append("activity_id", activity_id); - return fetch(`${getAPIUrl()}blocks/image`, RequestBodyForm("POST", formData)) + return fetch(`${getAPIUrl()}blocks/image`, RequestBodyForm("POST", formData, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } export async function getImageFile(file_id: string) { // todo : add course id to url - return fetch(`${getAPIUrl()}blocks/image?file_id=${file_id}`, RequestBody("GET", null)) + return fetch(`${getAPIUrl()}blocks/image?file_id=${file_id}`, RequestBody("GET", null, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } diff --git a/front/services/blocks/Pdf/pdf.ts b/front/services/blocks/Pdf/pdf.ts index fc9b4e5e..89b520f1 100644 --- a/front/services/blocks/Pdf/pdf.ts +++ b/front/services/blocks/Pdf/pdf.ts @@ -7,14 +7,14 @@ export async function uploadNewPDFFile(file: any, activity_id: string) { formData.append("file_object", file); formData.append("activity_id", activity_id); - return fetch(`${getAPIUrl()}blocks/pdf`, RequestBodyForm("POST", formData)) + return fetch(`${getAPIUrl()}blocks/pdf`, RequestBodyForm("POST", formData, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } export async function getPDFFile(file_id: string) { // todo : add course id to url - return fetch(`${getAPIUrl()}blocks/pdf?file_id=${file_id}`, RequestBody("GET", null)) + return fetch(`${getAPIUrl()}blocks/pdf?file_id=${file_id}`, RequestBody("GET", null, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } diff --git a/front/services/blocks/Quiz/quiz.ts b/front/services/blocks/Quiz/quiz.ts index 0adb85dd..60e921ed 100644 --- a/front/services/blocks/Quiz/quiz.ts +++ b/front/services/blocks/Quiz/quiz.ts @@ -3,7 +3,7 @@ import { RequestBody, RequestBodyForm } from "@services/utils/ts/requests"; export async function submitQuizBlock(activity_id: string, data: any) { - const result: any = await fetch(`${getAPIUrl()}blocks/quiz/${activity_id}"`, RequestBody("POST", data)) + const result: any = await fetch(`${getAPIUrl()}blocks/quiz/${activity_id}"`, RequestBody("POST", data, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); return result; diff --git a/front/services/blocks/Video/video.ts b/front/services/blocks/Video/video.ts index bf7142b4..714a2fc3 100644 --- a/front/services/blocks/Video/video.ts +++ b/front/services/blocks/Video/video.ts @@ -7,13 +7,13 @@ export async function uploadNewVideoFile(file: any, activity_id: string) { formData.append("file_object", file); formData.append("activity_id", activity_id); - return fetch(`${getAPIUrl()}blocks/video`, RequestBodyForm("POST", formData)) + return fetch(`${getAPIUrl()}blocks/video`, RequestBodyForm("POST", formData, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } export async function getVideoFile(file_id: string) { - return fetch(`${getAPIUrl()}blocks/video?file_id=${file_id}`, RequestBody("GET", null)) + return fetch(`${getAPIUrl()}blocks/video?file_id=${file_id}`, RequestBody("GET", null, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } diff --git a/front/services/courses/activities.ts b/front/services/courses/activities.ts index a7976e05..a87b398e 100644 --- a/front/services/courses/activities.ts +++ b/front/services/courses/activities.ts @@ -6,7 +6,7 @@ export async function createActivity(data: any, chapter_id: any, org_id: any) { // remove chapter_id from data delete data.chapterId; - const result = await fetch(`${getAPIUrl()}activities/?coursechapter_id=${chapter_id}&org_id=${org_id}`, RequestBody("POST", data)); + const result = await fetch(`${getAPIUrl()}activities/?coursechapter_id=${chapter_id}&org_id=${org_id}`, RequestBody("POST", data, null)); const res = await result.json(); return res; } @@ -31,7 +31,7 @@ export async function createFileActivity(file: File, type: string, data: any, ch // Handle other file types here } - const result: any = await fetch(endpoint, RequestBodyForm("POST", formData)); + const result: any = await fetch(endpoint, RequestBodyForm("POST", formData, null)); const res = await result.json(); return res; } @@ -41,19 +41,19 @@ export async function createExternalVideoActivity(data: any, activity: any, chap data.coursechapter_id = chapter_id; data.activity_id = activity.id; - const result = await fetch(`${getAPIUrl()}activities/external_video?coursechapter_id=${chapter_id}`, RequestBody("POST", data)); + const result = await fetch(`${getAPIUrl()}activities/external_video?coursechapter_id=${chapter_id}`, RequestBody("POST", data, null)); const res = await result.json(); return res; } -export async function getActivity(activity_id: any) { - const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("GET", null)); +export async function getActivity(activity_id: any, next: any) { + const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("GET", null,next)); const res = await result.json(); return res; } export async function updateActivity(data: any, activity_id: any) { - const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("PUT", data)); + const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("PUT", data, null)); const res = await result.json(); return res; } diff --git a/front/services/courses/activity.ts b/front/services/courses/activity.ts index aec4ec45..9ac90450 100644 --- a/front/services/courses/activity.ts +++ b/front/services/courses/activity.ts @@ -7,19 +7,19 @@ import { getAPIUrl } from "@services/config/config"; */ 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)) + const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/add_course/${course_id}`, 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)) + const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/remove_course/${course_id}`, RequestBody("POST", 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)) + 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)) const res = await errorHandling(result); return res; } diff --git a/front/services/courses/chapters.ts b/front/services/courses/chapters.ts index ddf2c521..eecaca41 100644 --- a/front/services/courses/chapters.ts +++ b/front/services/courses/chapters.ts @@ -7,27 +7,27 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ //TODO : depreciate this function -export async function getCourseChaptersMetadata(course_id: any) { - const result = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null)); +export async function getCourseChaptersMetadata(course_id: any, next: any) { + const result = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, 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)); + const result: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("PUT", data, null)); const res = await errorHandling(result); 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)); + const result: any = await fetch(`${getAPIUrl()}chapters/?course_id=course_${course_id}`, RequestBody("POST", data, null)); const res = await errorHandling(result); return res; } export async function deleteChapter(coursechapter_id: any) { - const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, RequestBody("DELETE", null)); + const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, RequestBody("DELETE", null, null)); const res = await errorHandling(result); return res; } diff --git a/front/services/courses/collections.ts b/front/services/courses/collections.ts index 9228fbc2..b3e4c027 100644 --- a/front/services/courses/collections.ts +++ b/front/services/courses/collections.ts @@ -7,14 +7,14 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function deleteCollection(collection_id: any) { - const result: any = await fetch(`${getAPIUrl()}collections/${collection_id}`, RequestBody("DELETE", null)); + const result: any = await fetch(`${getAPIUrl()}collections/${collection_id}`, RequestBody("DELETE", null, null)); const res = await errorHandling(result); return res; } // Create a new collection export async function createCollection(collection: any) { - const result: any = await fetch(`${getAPIUrl()}collections/`, RequestBody("POST", collection)); + const result: any = await fetch(`${getAPIUrl()}collections/`, RequestBody("POST", collection, null)); const res = await errorHandling(result); return res; } @@ -22,7 +22,7 @@ export async function createCollection(collection: any) { // Get collections // TODO : add per org filter export async function getOrgCollections() { - const result: any = await fetch(`${getAPIUrl()}collections/page/1/limit/10`); + const result: any = await fetch(`${getAPIUrl()}collections/page/1/limit/10`, { next: { revalidate: 10 } }); const res = await errorHandling(result); return res; } diff --git a/front/services/courses/courses.ts b/front/services/courses/courses.ts index f200f46b..ea1b4941 100644 --- a/front/services/courses/courses.ts +++ b/front/services/courses/courses.ts @@ -6,15 +6,15 @@ import { RequestBody, RequestBodyForm, errorHandling } from "@services/utils/ts/ GET requests are called from the frontend using SWR (https://swr.vercel.app/) */ -export async function getOrgCourses(org_id: number) { - const result: any = await fetch(`${getAPIUrl()}courses/org_slug/${org_id}/page/1/limit/10`, RequestBody("GET", null)); +export async function getOrgCourses(org_id: number, next: any) { + const result: any = await fetch(`${getAPIUrl()}courses/org_slug/${org_id}/page/1/limit/10`, RequestBody("GET", null, next)); const res = await errorHandling(result); return res; } -export async function getCourse(course_id: string) { - const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("GET", null)); +export async function getCourse(course_id: string, next: any) { + const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("GET", null, next)); const res = await errorHandling(result); return res; } @@ -28,13 +28,13 @@ export async function createNewCourse(org_id: string, course_body: any, thumbnai formData.append("mini_description", "course_body.mini_description"); formData.append("public", "true"); - const result = await fetch(`${getAPIUrl()}courses/?org_id=${org_id}`, RequestBodyForm("POST", formData)); + 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)); + const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("DELETE", null, null)); const res = await errorHandling(result); return res; } diff --git a/front/services/organizations/orgs.ts b/front/services/organizations/orgs.ts index 2718df70..56a11a94 100644 --- a/front/services/organizations/orgs.ts +++ b/front/services/organizations/orgs.ts @@ -7,19 +7,19 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function createNewOrganization(body: any) { - const result = await fetch(`${getAPIUrl()}orgs/`, RequestBody("POST", body)); + const result = await fetch(`${getAPIUrl()}orgs/`, RequestBody("POST", body, null)); const res = await errorHandling(result); return res; } export async function deleteOrganizationFromBackend(org_id: any) { - const result = await fetch(`${getAPIUrl()}orgs/${org_id}`, RequestBody("DELETE", null)); + const result = await fetch(`${getAPIUrl()}orgs/${org_id}`, RequestBody("DELETE", null, null)); const res = await errorHandling(result); return res; } -export async function getOrganizationContextInfo(org_slug: any) { - const result = await fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, RequestBody("GET", null)); +export async function getOrganizationContextInfo(org_slug: any, next: any) { + const result = await fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, RequestBody("GET", null,next)); const res = await errorHandling(result); return res; } diff --git a/front/services/settings/org.ts b/front/services/settings/org.ts index 1f4a0fd8..786eb56a 100644 --- a/front/services/settings/org.ts +++ b/front/services/settings/org.ts @@ -7,7 +7,7 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function updateOrganization(org_id: string, data: any) { - const result: any = await fetch(`${getAPIUrl()}orgs/` + org_id, RequestBody("PUT", data)); + const result: any = await fetch(`${getAPIUrl()}orgs/` + org_id, RequestBody("PUT", data, null)); const res = await errorHandling(result); return res; } diff --git a/front/services/settings/password.ts b/front/services/settings/password.ts index a93483f3..86d4a659 100644 --- a/front/services/settings/password.ts +++ b/front/services/settings/password.ts @@ -7,7 +7,7 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function updatePassword(user_id : string, data: any) { - const result: any = await fetch(`${getAPIUrl()}users/password/user_id/` + user_id, RequestBody("PUT", data)) + const result: any = await fetch(`${getAPIUrl()}users/password/user_id/` + user_id, RequestBody("PUT", data, null)) const res = await errorHandling(result); return res; } diff --git a/front/services/settings/profile.ts b/front/services/settings/profile.ts index 06f0667e..adfb3045 100644 --- a/front/services/settings/profile.ts +++ b/front/services/settings/profile.ts @@ -7,7 +7,7 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function updateProfile(data: any) { - const result: any = await fetch(`${getAPIUrl()}users/user_id/` + data.user_id, RequestBody("PUT", data)) + const result: any = await fetch(`${getAPIUrl()}users/user_id/` + data.user_id, RequestBody("PUT", data, null)) const res = await errorHandling(result); return res; } diff --git a/front/services/utils/ts/requests.ts b/front/services/utils/ts/requests.ts index 3df81e89..2d636be4 100644 --- a/front/services/utils/ts/requests.ts +++ b/front/services/utils/ts/requests.ts @@ -1,15 +1,15 @@ import { AppRouterInstance } from "next/dist/shared/lib/app-router-context"; import { denyAccessToUser } from "../react/middlewares/views"; -export const RequestBody = (method: string, data: any) => { +export const RequestBody = (method: string, data: any, next: any) => { let HeadersConfig = new Headers({ "Content-Type": "application/json" }); let options: any = { method: method, headers: HeadersConfig, redirect: "follow", credentials: "include", - // Next.js - cache: 'no-store' + // Next.js + next: next, }; if (data) { options.body = JSON.stringify(data); @@ -17,7 +17,7 @@ export const RequestBody = (method: string, data: any) => { return options; }; -export const RequestBodyForm = (method: string, data: any) => { +export const RequestBodyForm = (method: string, data: any, next: any) => { let HeadersConfig = new Headers({}); let options: any = { method: method, @@ -25,6 +25,8 @@ export const RequestBodyForm = (method: string, data: any) => { redirect: "follow", credentials: "include", body: data, + // Next.js + next: next, }; return options; };