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',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${process.env.LEANTIME_TOKEN}`,
|
||||
'apiKey': process.env.LEANTIME_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
jsonrpc: '2.0',
|
||||
method: 'leantime.rpc.users.getAll',
|
||||
id: 1,
|
||||
id: 1
|
||||
}),
|
||||
});
|
||||
|
||||
const responseText = await response.text();
|
||||
console.log('Raw Leantime response:', responseText);
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Failed to fetch Leantime users:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText
|
||||
statusText: response.statusText,
|
||||
headers: Object.fromEntries(response.headers.entries())
|
||||
});
|
||||
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);
|
||||
|
||||
if (!data.result || !Array.isArray(data.result)) {
|
||||
@ -86,28 +97,39 @@ export async function GET(request: NextRequest) {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${process.env.LEANTIME_TOKEN}`,
|
||||
'apiKey': process.env.LEANTIME_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
jsonrpc: '2.0',
|
||||
method: 'leantime.rpc.tickets.getAll',
|
||||
params: {
|
||||
userId: userId,
|
||||
status: "all",
|
||||
status: "all"
|
||||
},
|
||||
id: 1,
|
||||
id: 1
|
||||
}),
|
||||
});
|
||||
|
||||
const responseText = await response.text();
|
||||
console.log('Raw tasks response:', responseText);
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Failed to fetch tasks from Leantime:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText
|
||||
statusText: response.statusText,
|
||||
headers: Object.fromEntries(response.headers.entries())
|
||||
});
|
||||
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:', {
|
||||
success: true,
|
||||
taskCount: data.result?.length || 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user