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

Function GET

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

Source from the content-addressed store, hash-verified

10import { eq, desc } from 'drizzle-orm'
11
12export async function GET(request: NextRequest): Promise<NextResponse> {
13 try {
14 // Check admin authentication
15 const authResult = await checkAdminAuth()
16 if (authResult instanceof NextResponse) {
17 return authResult
18 }
19
20 // Get all organizations with detailed information
21 const organizations = await db
22 .select({
23 id: schema.org.id,
24 name: schema.org.name,
25 slug: schema.org.slug,
26 description: schema.org.description,
27 owner_name: schema.user.name,
28 owner_email: schema.user.email,
29 created_at: schema.org.created_at,
30 updated_at: schema.org.updated_at,
31 stripe_customer_id: schema.org.stripe_customer_id,
32 auto_topup_enabled: schema.org.auto_topup_enabled,
33 auto_topup_threshold: schema.org.auto_topup_threshold,
34 auto_topup_amount: schema.org.auto_topup_amount,
35 credit_limit: schema.org.credit_limit,
36 billing_alerts: schema.org.billing_alerts,
37 usage_alerts: schema.org.usage_alerts,
38 })
39 .from(schema.org)
40 .innerJoin(schema.user, eq(schema.org.owner_id, schema.user.id))
41 .orderBy(desc(schema.org.created_at))
42
43 // Generate CSV
44 const csvHeaders = [
45 'Organization ID',
46 'Name',
47 'Slug',
48 'Description',
49 'Owner Name',
50 'Owner Email',
51 'Created At',
52 'Updated At',
53 'Stripe Customer ID',
54 'Auto Topup Enabled',
55 'Auto Topup Threshold',
56 'Auto Topup Amount',
57 'Credit Limit',
58 'Billing Alerts',
59 'Usage Alerts',
60 ]
61
62 const csvRows = organizations.map((org) => [
63 org.id,
64 org.name,
65 org.slug,
66 org.description || '',
67 org.owner_name || 'Unknown',
68 org.owner_email,
69 org.created_at.toISOString(),

Callers

nothing calls this directly

Calls 2

checkAdminAuthFunction · 0.90
fromMethod · 0.80

Tested by

no test coverage detected