File size: 1,782 Bytes
1ba9d5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
 * Maintainer Dashboard Route
 * 
 * Get dashboard stats, issues, and templates for maintainers.
 */

import { NextRequest, NextResponse } from "next/server";
import { getCurrentUser } from "@/lib/auth";
import { getDashboardStats, getIssuesWithTriage } from "@/lib/db/queries/issues";
import { getMaintainerRepositories, getRepositoryStats } from "@/lib/db/queries/repositories";

export async function GET(request: NextRequest) {
    try {
        const user = await getCurrentUser(request);
        if (!user) {
            return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
        }

        if (user.role !== "MAINTAINER" && user.role !== "maintainer") {
            return NextResponse.json({ error: "Maintainer access required" }, { status: 403 });
        }

        const { searchParams } = new URL(request.url);
        const page = parseInt(searchParams.get("page") || "1");
        const limit = parseInt(searchParams.get("limit") || "10");

        // Get dashboard data
        const [stats, repos, issuesData] = await Promise.all([
            getDashboardStats(user.id),
            getMaintainerRepositories(user.id),
            getIssuesWithTriage({ userId: user.id, state: "open" }, page, limit),
        ]);

        return NextResponse.json({
            stats,
            repositories: repos,
            issues: issuesData.issues,
            pagination: {
                page: issuesData.page,
                limit: issuesData.limit,
                total: issuesData.total,
                totalPages: issuesData.totalPages,
            }
        });
    } catch (error) {
        console.error("Maintainer dashboard error:", error);
        return NextResponse.json({ error: "Internal server error" }, { status: 500 });
    }
}