working leantime widget 13
This commit is contained in:
parent
6e64455ef2
commit
cbc14d1477
@ -52,10 +52,10 @@ export async function GET() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const userData = await userResponse.json();
|
if (!userResponse.ok) {
|
||||||
console.log('User lookup response:', userData);
|
const errorData = await userResponse.json();
|
||||||
|
console.error('User lookup failed:', errorData);
|
||||||
if (userData.error === 'Too many requests per minute.') {
|
if (userResponse.status === 429) {
|
||||||
const retryAfter = userResponse.headers.get('retry-after') || '60';
|
const retryAfter = userResponse.headers.get('retry-after') || '60';
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Rate limit exceeded. Please try again later." },
|
{ error: "Rate limit exceeded. Please try again later." },
|
||||||
@ -67,6 +67,11 @@ export async function GET() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
throw new Error('Failed to fetch user data from Leantime');
|
||||||
|
}
|
||||||
|
|
||||||
|
const userData = await userResponse.json();
|
||||||
|
console.log('User lookup response:', userData);
|
||||||
|
|
||||||
if (!userData.result || !userData.result.id) {
|
if (!userData.result || !userData.result.id) {
|
||||||
throw new Error('Could not find Leantime user ID');
|
throw new Error('Could not find Leantime user ID');
|
||||||
@ -86,7 +91,7 @@ export async function GET() {
|
|||||||
return NextResponse.json({ projects: cachedLabels.data });
|
return NextResponse.json({ projects: cachedLabels.data });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now fetch the status labels
|
// Now fetch the status labels using leantimeUserId
|
||||||
const response = await fetch('https://agilite.slm-lab.net/api/jsonrpc', {
|
const response = await fetch('https://agilite.slm-lab.net/api/jsonrpc', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -98,16 +103,19 @@ export async function GET() {
|
|||||||
method: 'leantime.rpc.Tickets.Tickets.getAllStatusLabelsByUserId',
|
method: 'leantime.rpc.Tickets.Tickets.getAllStatusLabelsByUserId',
|
||||||
id: 1,
|
id: 1,
|
||||||
params: {
|
params: {
|
||||||
userId: session.user.id
|
userId: leantimeUserId // Use the Leantime user ID here
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch status labels from Leantime');
|
const errorData = await response.json();
|
||||||
|
console.error('Status labels fetch failed:', errorData);
|
||||||
|
throw new Error(`Failed to fetch status labels: ${errorData.error || 'Unknown error'}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log('Status labels response:', data);
|
||||||
|
|
||||||
if (!data.result) {
|
if (!data.result) {
|
||||||
return NextResponse.json({ projects: [] });
|
return NextResponse.json({ projects: [] });
|
||||||
@ -120,7 +128,7 @@ export async function GET() {
|
|||||||
class: label.class,
|
class: label.class,
|
||||||
statusType: label.statusType,
|
statusType: label.statusType,
|
||||||
kanbanCol: label.kanbanCol,
|
kanbanCol: label.kanbanCol,
|
||||||
sortKey: parseInt(label.sortKey)
|
sortKey: Number(label.sortKey) || 0
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Sort labels by sortKey
|
// Sort labels by sortKey
|
||||||
@ -142,7 +150,7 @@ export async function GET() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching status labels:', error);
|
console.error('Error fetching status labels:', error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Failed to fetch status labels" },
|
{ error: error instanceof Error ? error.message : "Failed to fetch status labels" },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user