Files

38 lines
817 B
TypeScript
Raw Permalink Normal View History

2025-09-17 16:47:19 -06:00
import axios from "axios";
import { envConfig } from "./config";
2025-12-08 18:02:33 -06:00
import { redirect } from "next/navigation";
import { cookies } from "next/headers";
if (!envConfig.apiUrl) {
console.error("API URL is not defined in envConfig");
2025-12-08 18:02:33 -06:00
}
2025-09-17 16:47:19 -06:00
2025-09-22 12:15:32 -04:00
export async function GetStudent(numAcount: number) {
2025-12-08 18:02:33 -06:00
const cookieStore = cookies();
const token = (await cookieStore).get("token")?.value;
if (!token) redirect("/");
2025-09-17 16:47:19 -06:00
try {
2025-12-08 18:02:33 -06:00
const response = await axios.get(
`${envConfig.apiUrl}/student/${numAcount}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
}
2025-09-22 14:53:19 -06:00
);
2025-09-24 15:49:59 -06:00
2025-09-17 16:47:19 -06:00
return response.data;
2025-09-17 16:47:19 -06:00
} catch (error: any) {
return {
error:
error.response?.data?.message ||
"Error al obtener estudiante",
status: error.response?.status,
};
2025-09-17 16:47:19 -06:00
}
}
2025-09-22 14:53:19 -06:00
//IO