working leantime widget 40
This commit is contained in:
parent
b4cfe735ed
commit
30dc143ffd
@ -26,6 +26,8 @@ async function getLeantimeUserId(email: string): Promise<number | null> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log('Fetching Leantime users with token:', process.env.LEANTIME_TOKEN ? 'Token present' : 'Token missing');
|
||||||
|
|
||||||
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: {
|
||||||
@ -40,11 +42,18 @@ async function getLeantimeUserId(email: string): Promise<number | null> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch users from Leantime');
|
console.error('Failed to fetch users from Leantime:', {
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText
|
||||||
|
});
|
||||||
|
throw new Error(`Failed to fetch users from Leantime: ${response.status} ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log('Leantime users response:', data);
|
||||||
|
|
||||||
const user = data.result.find((u: any) => u.email === email);
|
const user = data.result.find((u: any) => u.email === email);
|
||||||
|
console.log('Found user:', user ? 'Yes' : 'No');
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
// Cache the user ID
|
// Cache the user ID
|
||||||
@ -64,6 +73,7 @@ async function getLeantimeUserId(email: string): Promise<number | null> {
|
|||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
console.log('Session:', session ? 'Present' : 'Missing');
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@ -79,8 +89,11 @@ export async function GET(request: NextRequest) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('User email:', session.user.email);
|
||||||
|
|
||||||
// Get Leantime user ID
|
// Get Leantime user ID
|
||||||
const leantimeUserId = await getLeantimeUserId(session.user.email);
|
const leantimeUserId = await getLeantimeUserId(session.user.email);
|
||||||
|
console.log('Leantime user ID:', leantimeUserId);
|
||||||
|
|
||||||
if (!leantimeUserId) {
|
if (!leantimeUserId) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@ -90,6 +103,7 @@ export async function GET(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get all tasks assigned to the user
|
// Get all tasks assigned to the user
|
||||||
|
console.log('Fetching tasks for user:', 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: {
|
||||||
@ -109,16 +123,22 @@ export async function GET(request: NextRequest) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch tasks from Leantime');
|
console.error('Failed to fetch tasks:', {
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText
|
||||||
|
});
|
||||||
|
throw new Error(`Failed to fetch tasks: ${response.status} ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log('Tasks response:', data);
|
||||||
|
|
||||||
if (!data.result) {
|
if (!data.result) {
|
||||||
return NextResponse.json({ projects: [] });
|
return NextResponse.json({ projects: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get project details to include project names
|
// Get project details to include project names
|
||||||
|
console.log('Fetching projects');
|
||||||
const projectsResponse = await fetch('https://agilite.slm-lab.net/api/jsonrpc', {
|
const projectsResponse = await fetch('https://agilite.slm-lab.net/api/jsonrpc', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -133,10 +153,15 @@ export async function GET(request: NextRequest) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!projectsResponse.ok) {
|
if (!projectsResponse.ok) {
|
||||||
throw new Error('Failed to fetch projects from Leantime');
|
console.error('Failed to fetch projects:', {
|
||||||
|
status: projectsResponse.status,
|
||||||
|
statusText: projectsResponse.statusText
|
||||||
|
});
|
||||||
|
throw new Error(`Failed to fetch projects: ${projectsResponse.status} ${projectsResponse.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const projectsData = await projectsResponse.json();
|
const projectsData = await projectsResponse.json();
|
||||||
|
console.log('Projects response:', projectsData);
|
||||||
|
|
||||||
// Create a map of projects with their tasks grouped by status
|
// Create a map of projects with their tasks grouped by status
|
||||||
const projectMap = new Map<string, Project>();
|
const projectMap = new Map<string, Project>();
|
||||||
@ -192,6 +217,7 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
// Convert the map to an array and sort projects by name
|
// Convert the map to an array and sort projects by name
|
||||||
const projects = Array.from(projectMap.values()).sort((a, b) => a.name.localeCompare(b.name));
|
const projects = Array.from(projectMap.values()).sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
console.log('Final projects:', projects);
|
||||||
|
|
||||||
return NextResponse.json({ projects });
|
return NextResponse.json({ projects });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user