This commit is contained in:
2024-10-08 15:29:36 +08:00
parent ae470a2e83
commit 73a1a4f0ca
2 changed files with 21 additions and 22 deletions

View File

@@ -42,13 +42,12 @@ export async function fetchAboutus() {
accept: "application/json"
};
const url = `${process.env.NEXT_PUBLIC_API_URL}aboutUs/`;
console.log('Fetching from URL:', url);
try {
const response = await fetch(url, { headers });
console.log('Response status:', response.status);
const result = await response.json();
console.log('Fetched data:', result);
// Sort the result by index
const sortedResult: AboutusProps[] = result.data.sort((a: any, b: any) => a.index - b.index);
@@ -72,10 +71,10 @@ export async function fetchCourses() {
try {
const response = await fetch(url, { headers });
console.log('Response status:', response.status);
const result = await response.json();
console.log('Fetched data:', result);
const coursesArray: CoursesProps[] = result.data.map((course: CoursesProps) => ({
...course,
@@ -89,7 +88,7 @@ export async function fetchCourses() {
return sortedCoursesArray;
} catch (error) {
console.error('Fetch error:', error);
throw error;
}
}
@@ -100,14 +99,14 @@ export async function fetchCourse(id: string) {
};
const url = `${process.env.NEXT_PUBLIC_API_URL}course/${id}/`;
console.log('Fetching from URL:', url);
try {
const response = await fetch(url, { headers });
console.log('Response status:', response.status);
var result: CoursesProps = await response.json();
console.log('Fetched data:', result);
if (result.info_images && Array.isArray(result.info_images)) {
result.info_images.sort((a, b) => a.index - b.index);
@@ -125,12 +124,12 @@ export async function fetchSettings() {
accept: "application/json"
};
const url = `${process.env.NEXT_PUBLIC_API_URL}setting/`;
console.log('Fetching from URL:', url);
try {
const response = await fetch(url, { headers });
console.log('Response status:', response.status);
const result: SettingsProps = await response.json();
console.log('Fetched data:', result);
return result;
}
catch (error) {