MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / GET

Function GET

web/src/app/api/admin/orgs/route.ts:14–126  ·  view source on GitHub ↗
(request: NextRequest)

Source from the content-addressed store, hash-verified

12export const dynamic = 'force-dynamic'
13
14export async function GET(request: NextRequest): Promise<NextResponse> {
15 try {
16 // Check admin authentication
17 const authResult = await checkAdminAuth()
18 if (authResult instanceof NextResponse) {
19 return authResult
20 }
21
22 // Get all organizations with their details
23 const organizations = await db
24 .select({
25 id: schema.org.id,
26 name: schema.org.name,
27 slug: schema.org.slug,
28 owner_id: schema.org.owner_id,
29 created_at: schema.org.created_at,
30 owner_name: schema.user.name,
31 })
32 .from(schema.org)
33 .innerJoin(schema.user, eq(schema.org.owner_id, schema.user.id))
34 .orderBy(desc(schema.org.created_at))
35
36 // Get member counts for each organization
37 const memberCounts = await db
38 .select({
39 org_id: schema.orgMember.org_id,
40 count: sql<number>`COUNT(*)`,
41 })
42 .from(schema.orgMember)
43 .groupBy(schema.orgMember.org_id)
44
45 // Get repository counts for each organization
46 const repoCounts = await db
47 .select({
48 org_id: schema.orgRepo.org_id,
49 count: sql<number>`COUNT(*)`,
50 })
51 .from(schema.orgRepo)
52 .where(eq(schema.orgRepo.is_active, true))
53 .groupBy(schema.orgRepo.org_id)
54
55 // Build the response with additional data
56 const now = new Date()
57 const currentMonthStart = new Date(now.getFullYear(), now.getMonth(), 1)
58
59 const organizationSummaries = await Promise.all(
60 organizations.map(async (org) => {
61 const memberCount =
62 memberCounts.find((m) => m.org_id === org.id)?.count || 0
63 const repositoryCount =
64 repoCounts.find((r) => r.org_id === org.id)?.count || 0
65
66 // Get credit balance and usage
67 let creditBalance = 0
68 let usageThisCycle = 0
69 let healthStatus: 'healthy' | 'warning' | 'critical' = 'healthy'
70
71 try {

Callers

nothing calls this directly

Calls 3

checkAdminAuthFunction · 0.90
fromMethod · 0.80

Tested by

no test coverage detected