This commit is contained in:
2024-10-08 13:35:35 +08:00
parent 3272da0b2b
commit bd0f852f8a
12 changed files with 79 additions and 20 deletions

View File

@@ -11,7 +11,7 @@ export async function postMessage(data: MessageProps) {
};
const body = JSON.stringify(data);
const url = `http://localhost/api/v1/messages/`;
const url = `${process.env.NEXT_PUBLIC_API_URL}messages/`;
try {
const response = await fetch(url, {
@@ -41,7 +41,7 @@ export async function fetchAboutus() {
const headers: HeadersInit = {
accept: "application/json"
};
const url = `${process.env.api_url}aboutUs`;
const url = `${process.env.NEXT_PUBLIC_API_URL}aboutUs/`;
console.log('Fetching from URL:', url);
try {
const response = await fetch(url, { headers });
@@ -67,7 +67,7 @@ export async function fetchCourses() {
accept: "application/json"
};
const url = `${process.env.api_url}course/?skip=0&limit=100`;
const url = `${process.env.NEXT_PUBLIC_API_URL}course/?skip=0&limit=100`;
console.log('Fetching from URL:', url);
try {
@@ -83,7 +83,11 @@ export async function fetchCourses() {
info_images: course?.info_images?.sort((a: any, b: any) => a.index - b.index),
}));
return coursesArray;
const sortedCoursesArray = coursesArray.sort((a, b) =>
new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
);
return sortedCoursesArray;
} catch (error) {
console.error('Fetch error:', error);
throw error;
@@ -95,7 +99,7 @@ export async function fetchCourse(id: string) {
accept: "application/json"
};
const url = `${process.env.api_url}course/${id}`;
const url = `${process.env.NEXT_PUBLIC_API_URL}course/${id}/`;
console.log('Fetching from URL:', url);
try {
@@ -120,7 +124,7 @@ export async function fetchSettings() {
const headers: HeadersInit = {
accept: "application/json"
};
const url = `${process.env.api_url}setting`;
const url = `${process.env.NEXT_PUBLIC_API_URL}setting/`;
console.log('Fetching from URL:', url);
try {
const response = await fetch(url, { headers });