working leantime widget 36

This commit is contained in:
Alma 2025-04-12 14:27:48 +02:00
parent cda5d7322d
commit 2b4958506a

View File

@ -37,6 +37,7 @@ async function getLeantimeUserId(email: string): Promise<number | null> {
});
if (!response.ok) {
console.error('Failed to fetch users from Leantime:', response.status, response.statusText);
throw new Error('Failed to fetch users from Leantime');
}
@ -51,6 +52,7 @@ async function getLeantimeUserId(email: string): Promise<number | null> {
return user.id;
}
console.error('User not found in Leantime:', email);
return null;
} catch (error) {
console.error('Error getting Leantime user ID:', error);
@ -61,15 +63,19 @@ async function getLeantimeUserId(email: string): Promise<number | null> {
export async function GET() {
try {
const session = await getServerSession(authOptions);
console.log('Session in tasks route:', session);
if (!session || !session.user?.email) {
console.error('Unauthorized: No session or email found');
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
// Get Leantime user ID
const leantimeUserId = await getLeantimeUserId(session.user.email);
console.log('Leantime user ID:', leantimeUserId);
if (!leantimeUserId) {
console.error('User not found in Leantime:', session.user.email);
return NextResponse.json({ error: "User not found in Leantime" }, { status: 404 });
}
@ -93,10 +99,12 @@ export async function GET() {
});
if (!response.ok) {
console.error('Failed to fetch tasks from Leantime:', response.status, response.statusText);
throw new Error('Failed to fetch tasks from Leantime');
}
const data = await response.json();
console.log('Tasks response:', data);
if (!data.result) {
return NextResponse.json({ tasks: [] });
@ -117,6 +125,7 @@ export async function GET() {
});
if (!projectsResponse.ok) {
console.error('Failed to fetch projects from Leantime:', projectsResponse.status, projectsResponse.statusText);
throw new Error('Failed to fetch projects from Leantime');
}
@ -150,7 +159,7 @@ export async function GET() {
return NextResponse.json({ tasks });
} catch (error) {
console.error('Error fetching tasks:', error);
console.error('Error in tasks route:', error);
return NextResponse.json(
{ error: "Failed to fetch tasks" },
{ status: 500 }