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