working leantime widget 48
This commit is contained in:
parent
1f8090e1ff
commit
bc9c2dbe1f
@ -25,24 +25,35 @@ async function getLeantimeUserId(email: string): Promise<number | null> {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': `Bearer ${process.env.LEANTIME_TOKEN}`,
|
'apiKey': process.env.LEANTIME_TOKEN
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method: 'leantime.rpc.users.getAll',
|
method: 'leantime.rpc.users.getAll',
|
||||||
id: 1,
|
id: 1
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const responseText = await response.text();
|
||||||
|
console.log('Raw Leantime response:', responseText);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error('Failed to fetch Leantime users:', {
|
console.error('Failed to fetch Leantime users:', {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
statusText: response.statusText
|
statusText: response.statusText,
|
||||||
|
headers: Object.fromEntries(response.headers.entries())
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
let data;
|
||||||
|
try {
|
||||||
|
data = JSON.parse(responseText);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to parse Leantime response:', e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Leantime users response:', data);
|
console.log('Leantime users response:', data);
|
||||||
|
|
||||||
if (!data.result || !Array.isArray(data.result)) {
|
if (!data.result || !Array.isArray(data.result)) {
|
||||||
@ -86,28 +97,39 @@ export async function GET(request: NextRequest) {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': `Bearer ${process.env.LEANTIME_TOKEN}`,
|
'apiKey': process.env.LEANTIME_TOKEN
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method: 'leantime.rpc.tickets.getAll',
|
method: 'leantime.rpc.tickets.getAll',
|
||||||
params: {
|
params: {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
status: "all",
|
status: "all"
|
||||||
},
|
},
|
||||||
id: 1,
|
id: 1
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const responseText = await response.text();
|
||||||
|
console.log('Raw tasks response:', responseText);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error('Failed to fetch tasks from Leantime:', {
|
console.error('Failed to fetch tasks from Leantime:', {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
statusText: response.statusText
|
statusText: response.statusText,
|
||||||
|
headers: Object.fromEntries(response.headers.entries())
|
||||||
});
|
});
|
||||||
throw new Error('Failed to fetch tasks from Leantime');
|
throw new Error('Failed to fetch tasks from Leantime');
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
let data;
|
||||||
|
try {
|
||||||
|
data = JSON.parse(responseText);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to parse tasks response:', e);
|
||||||
|
throw new Error('Invalid response format from Leantime');
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Leantime tasks response:', {
|
console.log('Leantime tasks response:', {
|
||||||
success: true,
|
success: true,
|
||||||
taskCount: data.result?.length || 0
|
taskCount: data.result?.length || 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user